@gate-forge/pack-sqlalchemy 0.23.0 → 0.24.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gate-forge/pack-sqlalchemy",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "SQLAlchemy CRUD discovery pack: AST-only python detector (GPP/3), in-process TS discover entry, configurable plane mapping, entity-adapter schema.",
6
6
  "type": "module",
@@ -29,8 +29,8 @@
29
29
  "test": "vitest run"
30
30
  },
31
31
  "dependencies": {
32
- "@gate-forge/core": "^0.23.0",
33
- "@gate-forge/plugin-protocol": "^0.23.0",
32
+ "@gate-forge/core": "^0.24.0",
33
+ "@gate-forge/plugin-protocol": "^0.24.0",
34
34
  "yaml": "^2.8.1",
35
35
  "zod": "^4.1.5"
36
36
  },
@@ -188,6 +188,14 @@ def _binding_source(own, name):
188
188
  return None
189
189
 
190
190
 
191
+ def _is_cursor(own, fn, name):
192
+ """True when ``name`` is bound exactly once in the scope, to ``X.cursor()``, and is no parameter."""
193
+ if _bound_count(own, name) != 1 or any(p.arg == name for p in _param_nodes(fn)):
194
+ return False
195
+ source = _binding_source(own, name)
196
+ return isinstance(source, ast.Call) and isinstance(source.func, ast.Attribute) and source.func.attr == "cursor"
197
+
198
+
191
199
  def _table_key(table):
192
200
  return (table[0], table[1] or "", table[2])
193
201
 
@@ -293,9 +301,20 @@ class _Walker:
293
301
  return hits[0] if len(hits) == 1 else None
294
302
 
295
303
  def _table_of(self, rel, own, fn, node):
296
- """The table an expression denotes: a model, ``M.__table__``, or ``table("lit")``."""
304
+ """The table an expression denotes.
305
+
306
+ A model, ``M.__table__``, ``table("lit")``, or a name bound exactly
307
+ once in the function to ``table("lit")``.
308
+ """
297
309
  if isinstance(node, ast.Name):
298
- return self._class_table(rel, node.id)
310
+ is_param = any(p.arg == node.id for p in _param_nodes(fn))
311
+ source = _binding_source(own, node.id)
312
+ if not is_param and source is None:
313
+ return self._class_table(rel, node.id)
314
+ # A parameter or a plain binding in this scope decides, not a model of that name.
315
+ if fn is None or is_param or _bound_count(own, node.id) != 1 or not isinstance(source, ast.Call):
316
+ return None
317
+ return self._table_of(rel, own, fn, source)
299
318
  if isinstance(node, ast.Attribute) and node.attr == "__table__" and isinstance(node.value, ast.Name):
300
319
  return self._class_table(rel, node.value.id)
301
320
  if isinstance(node, ast.Call) and self._sa_symbol(rel, node.func, own, fn) == "table" and node.args:
@@ -365,7 +384,7 @@ class _Walker:
365
384
  return []
366
385
 
367
386
  def _method_writes(self, rel, own, fn, call):
368
- """Writes made by a method call: ``X.__table__.insert()``, alembic ops and session adds."""
387
+ """Writes made by a method call: ``X.__table__.insert()``, alembic ops, cursor literals and session adds."""
369
388
  func = call.func
370
389
  if func.attr in WRITE_CALLS and isinstance(func.value, ast.Attribute) and func.value.attr == "__table__":
371
390
  return _listed(self._table_of(rel, own, fn, func.value))
@@ -375,6 +394,8 @@ class _Walker:
375
394
  return _listed(self._table_of(rel, own, fn, call.args[0]))
376
395
  if func.attr == "execute" and self._is_alembic_op(rel, func.value):
377
396
  return self._literal_write(_str_const(call.args[0]))
397
+ if func.attr == "execute" and isinstance(func.value, ast.Name) and _is_cursor(own, fn, func.value.id):
398
+ return self._literal_write(_str_const(call.args[0]))
378
399
  if (
379
400
  func.attr in SESSION_ADD_CALLS
380
401
  and isinstance(func.value, ast.Name)