shotgrid-orm 0.3.2__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shotgrid_orm
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Shotgrid SQLAlchemy ORM Generator - creates Python classes from a schema.
5
5
  Author-email: John Em Tran <johnemtran@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "shotgrid_orm"
3
- version = "0.3.2"
3
+ version = "0.3.4"
4
4
  authors = [
5
5
  { name="John Em Tran", email="johnemtran@gmail.com" },
6
6
  ]
@@ -36,6 +36,7 @@ sg_types = {
36
36
  "currency": {"hint": Mapped[float], "type": mapped_column(Float)},
37
37
  "date": {"hint": Mapped[str], "type": mapped_column(String)},
38
38
  "date_time": {"hint": Mapped[datetime], "type": mapped_column(DateTime)},
39
+ "duration": {"hint": Mapped[int], "type": mapped_column(Integer)},
39
40
  # NOTE: Entity types are stored as integer IDs. Relationship mappings are handled
40
41
  # in classes.py by creating _id and _type fields for polymorphic associations.
41
42
  # Full SQLAlchemy relationship() support could be added in future versions.
@@ -71,6 +72,7 @@ sg_types_optional = {
71
72
  "currency": {"hint": Mapped[Optional[float]], "type": mapped_column(Float)},
72
73
  "date": {"hint": Mapped[Optional[str]], "type": mapped_column(String)},
73
74
  "date_time": {"hint": Mapped[Optional[datetime]], "type": mapped_column(DateTime)},
75
+ "duration": {"hint": Mapped[Optional[int]], "type": mapped_column(Integer)},
74
76
  # NOTE: Entity types are stored as integer IDs. Relationship mappings are handled
75
77
  # in classes.py by creating _id and _type fields for polymorphic associations.
76
78
  "entity": {"hint": Mapped[Optional[int]], "type": mapped_column(Integer)},
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shotgrid_orm
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Shotgrid SQLAlchemy ORM Generator - creates Python classes from a schema.
5
5
  Author-email: John Em Tran <johnemtran@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -276,3 +276,62 @@ def test_entity_field_fk_enforced_in_db(sg_orm, test_db_path):
276
276
  asset_fks = inspector.get_foreign_keys("Asset")
277
277
  entity_source_fks = [fk for fk in asset_fks if "entity_source_id" in fk["constrained_columns"]]
278
278
  assert len(entity_source_fks) == 0, "Asset.entity_source_id must NOT have a FK (polymorphic field)"
279
+
280
+
281
+ def test_duration_field_type(tmp_path):
282
+ """duration fields are numeric (integer minutes) and persist as Integer columns."""
283
+ import json
284
+
285
+ from sqlalchemy.types import Integer
286
+
287
+ schema = {
288
+ "Task": {
289
+ "name": {"visible": True},
290
+ "fields": {
291
+ "id": {
292
+ "data_type": {"value": "number"},
293
+ "editable": False,
294
+ "entity_type": {"value": "Task"},
295
+ "mandatory": {"value": False},
296
+ "name": {"value": "id"},
297
+ "properties": {"default_value": {"value": None}},
298
+ "unique": False,
299
+ "visible": {"value": True},
300
+ },
301
+ "duration": {
302
+ "data_type": {"value": "duration"},
303
+ "editable": True,
304
+ "entity_type": {"value": "Task"},
305
+ "mandatory": {"value": False},
306
+ "name": {"value": "duration"},
307
+ "properties": {"default_value": {"value": None}},
308
+ "unique": False,
309
+ "visible": {"value": True},
310
+ },
311
+ },
312
+ }
313
+ }
314
+
315
+ schema_path = tmp_path / "schema.json"
316
+ schema_path.write_text(json.dumps(schema))
317
+
318
+ orm = SGORM(sg_schema_type=SchemaType.JSON_FILE, sg_schema_source=str(schema_path), echo=False)
319
+ Task = orm["Task"]
320
+ assert Task is not None
321
+ assert hasattr(Task, "duration")
322
+
323
+ engine = create_engine("sqlite+pysqlite:///:memory:", echo=False)
324
+ orm.Base.metadata.create_all(engine)
325
+
326
+ # Duration column must map to an integer type.
327
+ duration_col = next(c for c in Task.__table__.columns if c.name == "duration")
328
+ assert isinstance(duration_col.type, Integer)
329
+
330
+ # Round-trip a value to ensure persistence works.
331
+ session = Session(engine)
332
+ task = Task(id=1, duration=120)
333
+ session.add(task)
334
+ session.commit()
335
+ retrieved = session.get(Task, 1)
336
+ assert retrieved.duration == 120
337
+ session.close()
File without changes
File without changes
File without changes