codeant-ai-for-open-source[bot] commented on code in PR #42222:
URL: https://github.com/apache/superset/pull/42222#discussion_r3611491497


##########
superset/connectors/sqla/models.py:
##########
@@ -961,6 +961,7 @@ class TableColumn(AuditMixinNullable, ImportExportMixin, 
CertificationMixin, Mod
     table: Mapped["SqlaTable"] = relationship(
         "SqlaTable",
         back_populates="columns",
+        cascade_backrefs=False,

Review Comment:
   **Suggestion:** Setting this relationship to disable backref cascading can 
cause newly created child objects to be silently left out of the session when 
they are attached via reverse assignment, so expected column inserts may never 
be flushed. If any code path creates a column with `column.table = table` and 
only persists the table graph, you need to explicitly add each column to the 
session or keep backref save-update cascading enabled. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Dataset column creation via ORM fails to persist rows.
   - ⚠️ Metadata refresh may silently skip saving new columns.
   - ⚠️ Administrators see datasets without expected column definitions.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with the PR code, so `TableColumn.table` relationship at
   `superset/connectors/sqla/models.py:961-965` uses `cascade_backrefs=False`.
   
   2. Trigger a dataset metadata refresh or creation that constructs columns via
   `TableColumn(table=sqla_table, ...)` (same module 
`superset/connectors/sqla/models.py`, in
   the `SqlaTable` helper that builds `TableColumn` instances from inspector 
metadata).
   
   3. In this flow, the `SqlaTable` instance is added to the SQLAlchemy 
session, but the new
   `TableColumn` instances rely on the `table` assignment (`column.table = 
sqla_table`) and
   backref cascade to be pulled into the session; they are not explicitly 
`session.add()`-ed
   nor appended through `sqla_table.columns.append(column)`.
   
   4. On flush, because `cascade_backrefs=False` at 
`superset/connectors/sqla/models.py:964`,
   the ORM does not cascade `save-update` from `SqlaTable.columns` to these 
newly-associated
   `TableColumn` objects, so expected column rows are never inserted into the 
`columns`
   table; the dataset is created/refreshed without persisted column records.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1cd182668921473688bdc92a2651f2c1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1cd182668921473688bdc92a2651f2c1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/connectors/sqla/models.py
   **Line:** 964:964
   **Comment:**
        *Logic Error: Setting this relationship to disable backref cascading 
can cause newly created child objects to be silently left out of the session 
when they are attached via reverse assignment, so expected column inserts may 
never be flushed. If any code path creates a column with `column.table = table` 
and only persists the table graph, you need to explicitly add each column to 
the session or keep backref save-update cascading enabled.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42222&comment_hash=a6d43ea7143f8308ef3abf50f1f56352d0780f78d92d08d1d4fdbbe79982ea62&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42222&comment_hash=a6d43ea7143f8308ef3abf50f1f56352d0780f78d92d08d1d4fdbbe79982ea62&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to