python-general-be-lib 0.8.1__py3-none-any.whl → 0.8.3__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.
@@ -45,15 +45,19 @@ class Base:
45
45
  default_values = dict()
46
46
  mapper: Mapper = inspect(cls)
47
47
 
48
- column_properties = [prop for prop in mapper.column_attrs if include_only is None or prop.key in include_only]
48
+ # ``mapper.columns`` è indicizzato per **nome di attributo** e non forza la
49
+ # configurazione dei mapper: ``column_attrs``/``attrs``/``relationships`` la
50
+ # forzerebbero, e chiamare ``to_pydantic`` a import-time — il pattern
51
+ # documentato — romperebbe le relationship con forward-ref non ancora
52
+ # risolvibili (stessa ragione per cui ``relationship_attributes`` è lazy).
53
+ selected = [(name, column) for name, column in mapper.columns.items()
54
+ if include_only is None or name in include_only]
49
55
 
50
56
  model_name = f"{cls.__name__}Model" if not model_name else model_name
51
57
  fields = dict()
52
- field_values = {prop.key: None if full_optional else ... for prop in column_properties}
58
+ field_values = {name: None if full_optional else ... for name, _ in selected}
53
59
  field_values.update(default_values)
54
- for prop in column_properties:
55
- col = prop.columns[0]
56
- field_name = prop.key
60
+ for field_name, col in selected:
57
61
  if isinstance(col.type, Geometry):
58
62
  field_type = Optional[WKBElement] if col.nullable or full_optional else WKBElement
59
63
  else:
@@ -32,6 +32,7 @@ def _list_adapter(model: Type[BaseModel]) -> TypeAdapter:
32
32
  """
33
33
  return TypeAdapter(list[model])
34
34
 
35
+
35
36
  @lru_cache(maxsize=None)
36
37
  def _reduced_model(entity: Type[Base], columns: frozenset[str]) -> Type[BaseModel]:
37
38
  """Modello ridotto alle colonne indicate, costruito una volta per combinazione.
@@ -41,7 +42,9 @@ def _reduced_model(entity: Type[Base], columns: frozenset[str]) -> Type[BaseMode
41
42
  ricostruire il TypeAdapter — mancherebbe il bersaglio a ogni richiesta, e il suo
42
43
  `maxsize=None` tratterebbe una voce per classe generata.
43
44
  """
44
- ordinate = [prop.key for prop in inspect(entity).column_attrs if prop.key in columns]
45
+ # ``mapper.columns`` è indicizzato per nome di attributo e non forza la
46
+ # configurazione dei mapper (a differenza di ``column_attrs``/``attrs``).
47
+ ordinate = [name for name in inspect(entity).columns.keys() if name in columns]
45
48
  digest = hashlib.sha1("|".join(ordinate).encode()).hexdigest()[:8]
46
49
  return entity.to_pydantic(
47
50
  model_name=f"{entity.__name__}_{digest}",
@@ -127,11 +130,8 @@ class CrudRepository[Entity: Base | Type[Base]]:
127
130
 
128
131
  # -------------------------
129
132
 
130
-
131
-
132
-
133
133
  def _retrieve_parsing_model(self, columns=None, exclude_columns=None):
134
- selected_columns = set(columns) if columns else set(self.entity.__mapper__.attrs.keys()) # o columns_names corretto
134
+ selected_columns = set(columns) if columns else set(inspect(self.entity).columns.keys())
135
135
  if exclude_columns:
136
136
  selected_columns -= set(exclude_columns)
137
137
  if columns is None and not exclude_columns:
@@ -711,7 +711,7 @@ class CrudRepository[Entity: Base | Type[Base]]:
711
711
  entities = self.execute(session, stmt)
712
712
 
713
713
  len_entities = len(entities)
714
- if limit == 0 or (len_entities < limit and page == 1):
714
+ if limit == 0 or limit is None or (len_entities < limit and page == 1):
715
715
  count_ = len_entities
716
716
  elif limit > len_entities > 0 and page > 1:
717
717
  count_ = (page - 1) * limit + len_entities
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-general-be-lib
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: General purpose backend library — SQLAlchemy CRUD/Geometry repositories, FastAPI exceptions, Pydantic base models, logger utilities.
5
5
  Author-email: Andrea Di Placido <a.diplacido@arpes.it>, "Arpes S.r.l." <it.admin@arpes.it>
6
6
  License: MIT
@@ -8,12 +8,12 @@ general/exception/crud_exceptions.py,sha256=C2XPcCDctTAt20-we3II4WbSEb4yCQK4MjgV
8
8
  general/exception/exception_interface.py,sha256=TJ2Yd_RgwP22DWCzNXQSEAMXdRJsAoOH07RLBjY5IwU,1577
9
9
  general/interface/base/__init__.py,sha256=SDlTi28M8rzJ9yiKefo5l7V3K109LnnBHW-SuZ-5JtM,58
10
10
  general/interface/base/base_model.py,sha256=Tsy70uC6HHe194ZrQaX7pXROqobOkZIOB63VdagmFHE,2561
11
- general/interface/base/declarative_base.py,sha256=MB0xuANOM7RouB-n2BrMU__TvB0JocQRDXuEoH8geqs,5769
11
+ general/interface/base/declarative_base.py,sha256=GoW88wHg2cY7mCQCwxHXCIxI8KZiPiP3CDIFpRIOMHE,6135
12
12
  general/interface/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  general/interface/metadata/crud_metadata.py,sha256=BFohkkpUd7w211NYqAD20X4ZpovrXH7BERA1_Rs4Dv0,23291
14
14
  general/interface/metadata/geom_metadata.py,sha256=J5SMXMiDUXnzt7bNH12LIQO6S7jcLNf7Cm4CdLXv8Lg,12255
15
15
  general/interface/repository/__init__.py,sha256=EcRukwf61Ua-9-JfM_ingVv1wXNRV8HBrrWwjj8m23w,136
16
- general/interface/repository/crud_repository.py,sha256=UuHOEFDucEDjWvye7HYwTcSX4vwwCgYUnTVYNnFijrg,39604
16
+ general/interface/repository/crud_repository.py,sha256=AdnI5nFb0G0V4eTIjXALTVvJ5aiV50xpI0pIh1S9S2w,39740
17
17
  general/interface/repository/geometry_repository.py,sha256=WUnYOr0YOKNt7_lBa5HlbkGAkYuAaSrXqK7i0BQOctw,12101
18
18
  general/interface/repository/many_to_many_repository.py,sha256=ZyuK2fk5ZI9xE8xhZwk5Vb1QItnOxwEF5CGsemnMdn8,9197
19
19
  general/interface/repository/view_repository.py,sha256=ZqekhnSvHH_CJFb546tjUwnwGbwzyxZMx-f7yUvOl50,6206
@@ -25,8 +25,8 @@ general/interface/repository/handler/json_handler.py,sha256=XNAgIkUGQX8ttTsqtqE8
25
25
  general/interface/repository/handler/json_ilike_handler.py,sha256=NXqcS1YOtcOStdl7sp2cYqFMkEdcxoVmaNJewJEzL3M,4738
26
26
  general/interface/repository/handler/or_handler.py,sha256=hZ4Nc-nTi7Nh-krPUIlyCEg3q6H0D96T_oMVAzxezKY,4839
27
27
  general/interface/repository/handler/statement_manager.py,sha256=yCMR1vNnXYmmY4HwI2CDZLI513GzyVZniN31QJFGKKA,7080
28
- python_general_be_lib-0.8.1.dist-info/licenses/LICENSE,sha256=iUaO1XZyB9P3Tmog0OILuTisP6vXGe3QKz-4yRTxOFk,1069
29
- python_general_be_lib-0.8.1.dist-info/METADATA,sha256=AFjXFDilBkjVHWKCwEpK9yy0BkpFY_Clf8B4GW-Ihr8,2962
30
- python_general_be_lib-0.8.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- python_general_be_lib-0.8.1.dist-info/top_level.txt,sha256=tTZePW8_CNUqSgKFd2SEH72ZbnhS0OYjRsgcv0ikSFY,8
32
- python_general_be_lib-0.8.1.dist-info/RECORD,,
28
+ python_general_be_lib-0.8.3.dist-info/licenses/LICENSE,sha256=iUaO1XZyB9P3Tmog0OILuTisP6vXGe3QKz-4yRTxOFk,1069
29
+ python_general_be_lib-0.8.3.dist-info/METADATA,sha256=Kjj0vny9_DD5ICWvqKD2NLUl7b6n3p-lkn7_g8ixYIw,2962
30
+ python_general_be_lib-0.8.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ python_general_be_lib-0.8.3.dist-info/top_level.txt,sha256=tTZePW8_CNUqSgKFd2SEH72ZbnhS0OYjRsgcv0ikSFY,8
32
+ python_general_be_lib-0.8.3.dist-info/RECORD,,