statikk 0.1.20__tar.gz → 0.1.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {statikk-0.1.20 → statikk-0.1.21}/PKG-INFO +1 -1
  2. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/engine.py +11 -3
  3. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/PKG-INFO +1 -1
  4. {statikk-0.1.20 → statikk-0.1.21}/tests/test_engine.py +20 -2
  5. {statikk-0.1.20 → statikk-0.1.21}/.coveragerc +0 -0
  6. {statikk-0.1.20 → statikk-0.1.21}/.gitignore +0 -0
  7. {statikk-0.1.20 → statikk-0.1.21}/.readthedocs.yml +0 -0
  8. {statikk-0.1.20 → statikk-0.1.21}/AUTHORS.rst +0 -0
  9. {statikk-0.1.20 → statikk-0.1.21}/CHANGELOG.rst +0 -0
  10. {statikk-0.1.20 → statikk-0.1.21}/CONTRIBUTING.rst +0 -0
  11. {statikk-0.1.20 → statikk-0.1.21}/LICENSE.txt +0 -0
  12. {statikk-0.1.20 → statikk-0.1.21}/README.rst +0 -0
  13. {statikk-0.1.20 → statikk-0.1.21}/assets/favicon.png +0 -0
  14. {statikk-0.1.20 → statikk-0.1.21}/assets/logo.png +0 -0
  15. {statikk-0.1.20 → statikk-0.1.21}/docs/Makefile +0 -0
  16. {statikk-0.1.20 → statikk-0.1.21}/docs/_static/.gitignore +0 -0
  17. {statikk-0.1.20 → statikk-0.1.21}/docs/authors.rst +0 -0
  18. {statikk-0.1.20 → statikk-0.1.21}/docs/changelog.rst +0 -0
  19. {statikk-0.1.20 → statikk-0.1.21}/docs/conf.py +0 -0
  20. {statikk-0.1.20 → statikk-0.1.21}/docs/contributing.rst +0 -0
  21. {statikk-0.1.20 → statikk-0.1.21}/docs/index.rst +0 -0
  22. {statikk-0.1.20 → statikk-0.1.21}/docs/license.rst +0 -0
  23. {statikk-0.1.20 → statikk-0.1.21}/docs/readme.rst +0 -0
  24. {statikk-0.1.20 → statikk-0.1.21}/docs/requirements.txt +0 -0
  25. {statikk-0.1.20 → statikk-0.1.21}/docs/usage.rst +0 -0
  26. {statikk-0.1.20 → statikk-0.1.21}/pyproject.toml +0 -0
  27. {statikk-0.1.20 → statikk-0.1.21}/setup.cfg +0 -0
  28. {statikk-0.1.20 → statikk-0.1.21}/setup.py +0 -0
  29. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/__init__.py +0 -0
  30. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/conditions.py +0 -0
  31. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/expressions.py +0 -0
  32. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/fields.py +0 -0
  33. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/models.py +0 -0
  34. {statikk-0.1.20 → statikk-0.1.21}/src/statikk/typing.py +0 -0
  35. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/SOURCES.txt +0 -0
  36. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/dependency_links.txt +0 -0
  37. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/not-zip-safe +0 -0
  38. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/requires.txt +0 -0
  39. {statikk-0.1.20 → statikk-0.1.21}/src/statikk.egg-info/top_level.txt +0 -0
  40. {statikk-0.1.20 → statikk-0.1.21}/tests/conftest.py +0 -0
  41. {statikk-0.1.20 → statikk-0.1.21}/tests/test_expressions.py +0 -0
  42. {statikk-0.1.20 → statikk-0.1.21}/tests/test_models.py +0 -0
  43. {statikk-0.1.20 → statikk-0.1.21}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: statikk
3
- Version: 0.1.20
3
+ Version: 0.1.21
4
4
  Summary: statikk is a single table application (STA) library for DynamoDb.
5
5
  Home-page: https://github.com/terinia/statikk
6
6
  Author: Balint Biro
@@ -24,6 +24,14 @@ from aws_xray_sdk.core import patch_all
24
24
  patch_all()
25
25
 
26
26
 
27
+ DYNAMODB_CONTEXT = decimal.Context(
28
+ prec=38, # precision
29
+ rounding=decimal.ROUND_HALF_EVEN,
30
+ traps=[decimal.Overflow, decimal.Underflow, decimal.InvalidOperation],
31
+ )
32
+ decimal.setcontext(DYNAMODB_CONTEXT)
33
+
34
+
27
35
  class InvalidIndexNameError(Exception):
28
36
  pass
29
37
 
@@ -536,6 +544,8 @@ class Table:
536
544
 
537
545
  if actual_annotation is datetime or "datetime" in str(annotation) and value is not None:
538
546
  return datetime.fromtimestamp(int(value))
547
+ if isinstance(value, decimal.Decimal):
548
+ return float(value)
539
549
  if actual_annotation is float:
540
550
  return float(value)
541
551
  if actual_annotation is list:
@@ -550,15 +560,13 @@ class Table:
550
560
  return {self._deserialize_value(item, item_annotation) for item in value}
551
561
  if isinstance(value, dict):
552
562
  return {key: self._deserialize_value(item, annotation) for key, item in value.items() if item is not None}
553
- if isinstance(value, decimal.Decimal):
554
- return float(value)
555
563
  return value
556
564
 
557
565
  def _serialize_value(self, value: Any):
558
566
  if isinstance(value, datetime):
559
567
  return int(value.timestamp())
560
568
  if isinstance(value, float):
561
- return Decimal(value)
569
+ return DYNAMODB_CONTEXT.create_decimal_from_float(value)
562
570
  if isinstance(value, list):
563
571
  return [self._serialize_value(item) for item in value]
564
572
  if isinstance(value, set):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: statikk
3
- Version: 0.1.20
3
+ Version: 0.1.21
4
4
  Summary: statikk is a single table application (STA) library for DynamoDb.
5
5
  Home-page: https://github.com/terinia/statikk
6
6
  Author: Balint Biro
@@ -1,6 +1,6 @@
1
1
  from _decimal import Decimal
2
2
  from datetime import datetime, timezone
3
- from typing import List, Optional, Type
3
+ from typing import List, Optional, Type, Any
4
4
 
5
5
  import pytest
6
6
  from boto3.dynamodb.conditions import Attr
@@ -996,4 +996,22 @@ def test_add_child_node():
996
996
  my_database_model = MyDatabaseModel.query_hierarchy(hash_key=Equals("foo"))
997
997
  assert len(my_database_model.nested.list_nested) == 1
998
998
  assert len(my_database_model.nested.other_list_nested) == 1
999
- hierarchy = MyDatabaseModel.query_hierarchy(hash_key=Equals("foo"))
999
+
1000
+
1001
+ def test_nested_model_with_decimal():
1002
+ class MyModel(DatabaseModel):
1003
+ id: str
1004
+ foo: str = "foo"
1005
+ values: dict[str, Any]
1006
+
1007
+ @classmethod
1008
+ def index_definitions(cls) -> dict[str, IndexFieldConfig]:
1009
+ return {"main-index": IndexFieldConfig(pk_fields=["foo"], sk_fields=[FIELD_STATIKK_TYPE])}
1010
+
1011
+ _create_default_dynamodb_table([MyModel])
1012
+
1013
+ my_model = MyModel(id="foo", values={"bar": 1.23})
1014
+ my_model.save()
1015
+ my_model_deserialized = MyModel.get("foo")
1016
+ assert type(my_model_deserialized.values["bar"]) == float
1017
+ assert my_model_deserialized.values["bar"] == 1.23
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes