statikk 0.1.2__tar.gz → 0.1.4__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.2 → statikk-0.1.4}/PKG-INFO +1 -1
  2. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/models.py +13 -7
  3. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/PKG-INFO +1 -1
  4. {statikk-0.1.2 → statikk-0.1.4}/tests/test_models.py +4 -4
  5. {statikk-0.1.2 → statikk-0.1.4}/.coveragerc +0 -0
  6. {statikk-0.1.2 → statikk-0.1.4}/.gitignore +0 -0
  7. {statikk-0.1.2 → statikk-0.1.4}/.readthedocs.yml +0 -0
  8. {statikk-0.1.2 → statikk-0.1.4}/AUTHORS.rst +0 -0
  9. {statikk-0.1.2 → statikk-0.1.4}/CHANGELOG.rst +0 -0
  10. {statikk-0.1.2 → statikk-0.1.4}/CONTRIBUTING.rst +0 -0
  11. {statikk-0.1.2 → statikk-0.1.4}/LICENSE.txt +0 -0
  12. {statikk-0.1.2 → statikk-0.1.4}/README.rst +0 -0
  13. {statikk-0.1.2 → statikk-0.1.4}/assets/favicon.png +0 -0
  14. {statikk-0.1.2 → statikk-0.1.4}/assets/logo.png +0 -0
  15. {statikk-0.1.2 → statikk-0.1.4}/docs/Makefile +0 -0
  16. {statikk-0.1.2 → statikk-0.1.4}/docs/_static/.gitignore +0 -0
  17. {statikk-0.1.2 → statikk-0.1.4}/docs/authors.rst +0 -0
  18. {statikk-0.1.2 → statikk-0.1.4}/docs/changelog.rst +0 -0
  19. {statikk-0.1.2 → statikk-0.1.4}/docs/conf.py +0 -0
  20. {statikk-0.1.2 → statikk-0.1.4}/docs/contributing.rst +0 -0
  21. {statikk-0.1.2 → statikk-0.1.4}/docs/index.rst +0 -0
  22. {statikk-0.1.2 → statikk-0.1.4}/docs/license.rst +0 -0
  23. {statikk-0.1.2 → statikk-0.1.4}/docs/readme.rst +0 -0
  24. {statikk-0.1.2 → statikk-0.1.4}/docs/requirements.txt +0 -0
  25. {statikk-0.1.2 → statikk-0.1.4}/docs/usage.rst +0 -0
  26. {statikk-0.1.2 → statikk-0.1.4}/pyproject.toml +0 -0
  27. {statikk-0.1.2 → statikk-0.1.4}/setup.cfg +0 -0
  28. {statikk-0.1.2 → statikk-0.1.4}/setup.py +0 -0
  29. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/__init__.py +0 -0
  30. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/conditions.py +0 -0
  31. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/engine.py +0 -0
  32. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/expressions.py +0 -0
  33. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/fields.py +0 -0
  34. {statikk-0.1.2 → statikk-0.1.4}/src/statikk/typing.py +0 -0
  35. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/SOURCES.txt +0 -0
  36. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/dependency_links.txt +0 -0
  37. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/not-zip-safe +0 -0
  38. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/requires.txt +0 -0
  39. {statikk-0.1.2 → statikk-0.1.4}/src/statikk.egg-info/top_level.txt +0 -0
  40. {statikk-0.1.2 → statikk-0.1.4}/tests/conftest.py +0 -0
  41. {statikk-0.1.2 → statikk-0.1.4}/tests/test_engine.py +0 -0
  42. {statikk-0.1.2 → statikk-0.1.4}/tests/test_expressions.py +0 -0
  43. {statikk-0.1.2 → statikk-0.1.4}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
@@ -56,11 +56,13 @@ class IndexFieldConfig(BaseModel):
56
56
  class TrackingMixin:
57
57
  _original_hash: int = Field(exclude=True)
58
58
 
59
- @classmethod
60
- def should_track(cls) -> bool:
61
- return True
59
+ @property
60
+ def should_track(self) -> bool:
61
+ if self._parent is not None:
62
+ return self._parent.should_track
63
+ return False
62
64
 
63
- def __init__(self):
65
+ def init_tracking(self):
64
66
  self._original_hash = self._recursive_hash()
65
67
 
66
68
  def _recursive_hash(self) -> int:
@@ -72,6 +74,9 @@ class TrackingMixin:
72
74
  Returns:
73
75
  A hash value representing the model's non-model fields.
74
76
  """
77
+ if not self.should_track:
78
+ return 0
79
+
75
80
  values = []
76
81
  for field_name in self.model_fields:
77
82
  if not hasattr(self, field_name):
@@ -131,7 +136,7 @@ class TrackingMixin:
131
136
 
132
137
  @property
133
138
  def was_modified(self) -> bool:
134
- if self.should_track():
139
+ if self.should_track:
135
140
  return self._recursive_hash() != self._original_hash
136
141
 
137
142
  return True
@@ -173,7 +178,7 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
173
178
  range_key: Optional[Condition] = None,
174
179
  filter_condition: Optional[ComparisonCondition] = None,
175
180
  index_name: Optional[str] = None,
176
- ) -> T:
181
+ ) -> list[T]:
177
182
  return cls._table.query_index(
178
183
  hash_key=hash_key,
179
184
  model_class=cls,
@@ -253,10 +258,10 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
253
258
 
254
259
  @model_validator(mode="after")
255
260
  def initialize_tracking(self):
256
- self._original_hash = self._recursive_hash()
257
261
  self._model_types_in_hierarchy[self.type()] = type(self)
258
262
  if not self.is_nested():
259
263
  self._set_parent_references(self)
264
+ self.init_tracking()
260
265
 
261
266
  return self
262
267
 
@@ -351,6 +356,7 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
351
356
  field._parent = parent
352
357
  root._model_types_in_hierarchy[field.type()] = type(field)
353
358
  field._set_parent_references(root)
359
+ field.init_tracking()
354
360
 
355
361
  def _set_parent_references(self, root: DatabaseModel):
356
362
  for field_name, field_value in self:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
@@ -28,6 +28,10 @@ class MyDatabaseModel(DatabaseModel):
28
28
  foo: str
29
29
  nested: MyNestedDatabaseModel
30
30
 
31
+ @property
32
+ def should_track(self) -> bool:
33
+ return True
34
+
31
35
 
32
36
  class MyDatabaseModelWithList(DatabaseModel):
33
37
  foo: str
@@ -98,10 +102,6 @@ def test_tracking_disabled():
98
102
  foo: str = "foo"
99
103
  bar: str = "bar"
100
104
 
101
- @classmethod
102
- def should_track(cls) -> bool:
103
- return False
104
-
105
105
  my_database_model = MyDatabaseModel(foo="foo", bar="bar")
106
106
  assert my_database_model.was_modified is True # untracked models should always be marked as modified
107
107
  my_database_model.foo = "bar"
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
File without changes
File without changes