tigrbl_engine_pandas 0.1.1.dev2__tar.gz → 0.1.1.dev5__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: tigrbl_engine_pandas
3
- Version: 0.1.1.dev2
3
+ Version: 0.1.1.dev5
4
4
  Summary: Tigrbl engine plugin providing transactional pandas DataFrame sessions.
5
5
  Project-URL: Homepage, https://github.com/swarmauri/swarmauri-sdk
6
6
  Project-URL: Repository, https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/tigrbl_engine_pandas
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "tigrbl_engine_pandas"
7
- version = "0.1.1.dev2"
7
+ version = "0.1.1.dev5"
8
8
  description = "Tigrbl engine plugin providing transactional pandas DataFrame sessions."
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -220,10 +220,37 @@ class TransactionalDataFrameSession(TigrblSessionBase):
220
220
  self._dels.clear()
221
221
 
222
222
  # ---- CRUD primitives ----
223
+ @staticmethod
224
+ def _pk_default(model: type, pk: str) -> Any:
225
+ table = getattr(model, "__table__", None)
226
+ if table is None:
227
+ return None
228
+ try:
229
+ column = table.columns.get(pk)
230
+ except Exception:
231
+ return None
232
+ if column is None:
233
+ return None
234
+ default = getattr(column, "default", None)
235
+ if default is None:
236
+ return None
237
+ arg = getattr(default, "arg", None)
238
+ if callable(arg):
239
+ try:
240
+ return arg()
241
+ except TypeError:
242
+ # Some SQLAlchemy defaults accept a context parameter.
243
+ return arg(None)
244
+ return arg
245
+
223
246
  def _add_impl(self, obj: Any) -> Any:
224
247
  model = obj.__class__
225
248
  pk = _single_pk_name(model)
226
249
  ident = getattr(obj, pk)
250
+ if ident is None:
251
+ ident = self._pk_default(model, pk)
252
+ if ident is not None:
253
+ setattr(obj, pk, ident)
227
254
  if ident is None:
228
255
  raise ValueError(f"primary key {pk!r} must be set")
229
256
  row = {c: getattr(obj, c, None) for c in _model_columns(model)}
@@ -370,12 +397,20 @@ class TransactionalDataFrameSession(TigrblSessionBase):
370
397
  return entity
371
398
 
372
399
  def _all_subclasses(base: type) -> list[type]:
400
+ def _safe_subclasses(cls: type) -> list[type]:
401
+ try:
402
+ return list(cls.__subclasses__())
403
+ except TypeError:
404
+ # Some metaclass entries (e.g. ``type``) expose an unbound
405
+ # descriptor here; treat as leaf.
406
+ return []
407
+
373
408
  out: list[type] = []
374
- stack = list(base.__subclasses__())
409
+ stack = _safe_subclasses(base)
375
410
  while stack:
376
411
  cls = stack.pop()
377
412
  out.append(cls)
378
- stack.extend(cls.__subclasses__())
413
+ stack.extend(_safe_subclasses(cls))
379
414
  return out
380
415
 
381
416
  def _find_by_table(name: str) -> type | None: