statikk 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl

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.
statikk/engine.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  from datetime import datetime
3
- from typing import Any, Dict, Type, Optional, List, Union
3
+ from typing import Any, Dict, Type, Optional, List, Union, get_type_hints, get_origin, get_args
4
4
 
5
5
  import boto3
6
6
  from botocore.config import Config
@@ -623,6 +623,26 @@ class Table:
623
623
  data = self._serialize_item(enriched_item)
624
624
  batch.delete_item(Key=data)
625
625
 
626
+ def inspect_optional_field(self, model_class, field_name):
627
+ field_type = model_class.model_fields[field_name].annotation
628
+
629
+ is_optional = False
630
+ inner_type = field_type
631
+
632
+ if get_origin(field_type) is Union:
633
+ args = get_args(field_type)
634
+ if len(args) == 2 and args[1] is type(None):
635
+ is_optional = True
636
+ inner_type = args[0]
637
+
638
+ elif hasattr(field_type, "__origin__") and field_type.__origin__ is Union:
639
+ args = getattr(field_type, "__args__", [])
640
+ if len(args) == 2 and args[1] is type(None):
641
+ is_optional = True
642
+ inner_type = args[0]
643
+
644
+ return (is_optional, inner_type)
645
+
626
646
  def reconstruct_hierarchy(self, items: list[dict]) -> Optional[dict]:
627
647
  """
628
648
  Reconstructs a hierarchical dictionary structure from a flat list of dictionaries
@@ -704,7 +724,9 @@ class Table:
704
724
  if field_name.startswith("_"):
705
725
  continue
706
726
 
707
- field_type = field_info.annotation
727
+ is_optional, inner_type = self.inspect_optional_field(parent_model_class, field_name)
728
+
729
+ field_type = inner_type if is_optional else field_info.annotation
708
730
 
709
731
  if field_type == child_model_class:
710
732
  matching_fields.append((field_name, "single"))
statikk/models.py CHANGED
@@ -204,8 +204,19 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
204
204
 
205
205
  @property
206
206
  def should_delete(self) -> bool:
207
+ if self._is_any_parent_marked_for_deletion():
208
+ return True
209
+
207
210
  return self._should_delete or self.is_parent_changed()
208
211
 
212
+ def _is_any_parent_marked_for_deletion(self) -> bool:
213
+ current = self._parent
214
+ while current is not None:
215
+ if current._should_delete:
216
+ return True
217
+ current = current._parent
218
+ return False
219
+
209
220
  @classmethod
210
221
  def query(
211
222
  cls: Type[T],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.8
3
+ Version: 0.1.9
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
@@ -0,0 +1,12 @@
1
+ statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
2
+ statikk/conditions.py,sha256=63FYMR-UUaE-ZJEb_8CU721CQTwhajq39-BbokmKeMA,2166
3
+ statikk/engine.py,sha256=0jF5pUZJtr_lBZMEZXd7PGDerr26CLZUh91gy15Leac,33252
4
+ statikk/expressions.py,sha256=boAeGxZj2cDsXxoiX3IIEzfX9voSMQngi4-rE_jYeuE,12233
5
+ statikk/fields.py,sha256=LkMP5NnX7WS0HSLxI3Q-dMOrfaJ0SD7SayZxJU5Acgg,86
6
+ statikk/models.py,sha256=gzy_MV3LVsVlorqHencXyS7HCVV2QQ698aWK5bQIdFk,16115
7
+ statikk/typing.py,sha256=qfpegORcdODuILK3gvuD4SdcZA1a7Myn0yvscOLPHOM,68
8
+ statikk-0.1.9.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
9
+ statikk-0.1.9.dist-info/METADATA,sha256=ZvTT-xMgID_v5WgHYz13E_JLHtqflVz9naDu9Qh-9rA,3160
10
+ statikk-0.1.9.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
11
+ statikk-0.1.9.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
12
+ statikk-0.1.9.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
2
- statikk/conditions.py,sha256=63FYMR-UUaE-ZJEb_8CU721CQTwhajq39-BbokmKeMA,2166
3
- statikk/engine.py,sha256=x3TB4iMXSpLudwv0dRBGFapttbc8etg36SA_tSq0tGY,32362
4
- statikk/expressions.py,sha256=boAeGxZj2cDsXxoiX3IIEzfX9voSMQngi4-rE_jYeuE,12233
5
- statikk/fields.py,sha256=LkMP5NnX7WS0HSLxI3Q-dMOrfaJ0SD7SayZxJU5Acgg,86
6
- statikk/models.py,sha256=X2MRFn3TAmKdxUQ9KDO9oNoekct4F3QBdcB1COtCpDU,15785
7
- statikk/typing.py,sha256=qfpegORcdODuILK3gvuD4SdcZA1a7Myn0yvscOLPHOM,68
8
- statikk-0.1.8.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
9
- statikk-0.1.8.dist-info/METADATA,sha256=9TYBs4MKqRMN2TJN6iRyl3g8nWSIG_zBlVnAAUtfClc,3160
10
- statikk-0.1.8.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
11
- statikk-0.1.8.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
12
- statikk-0.1.8.dist-info/RECORD,,