Skip to content

Fix detached-instance crash on GraphQL dimensionLinks.foreignKeys#2034

Merged
shangyian merged 4 commits intoDataJunction:mainfrom
shangyian:fix-gql-find-nodes
Apr 20, 2026
Merged

Fix detached-instance crash on GraphQL dimensionLinks.foreignKeys#2034
shangyian merged 4 commits intoDataJunction:mainfrom
shangyian:fix-gql-find-nodes

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented Apr 20, 2026

Summary

Querying findNodes { current { dimensionLinks { foreignKeys } } } was failing with a SQLAlchemy detached-instance error introduced by the per-resolver-session refactor (#2028). The dimension_links resolver was returning raw ORM DimensionLink objects and by the time Strawberry resolved the foreignKeys field, the session that loaded those objects had closed, so the lazy load of foreign_keys blew up.

Parent instance <DimensionLink at 0x7f200f9a2bd0> is not bound to a Session; lazy load operation of attribute 'node_revision' cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)

The fix is for the dimension_links resolver to turn each link into a Strawberry DimensionLink object, including foreign_keys, so that every attribute is realized while the parent resolver's session is still open and nothing lazy crosses the session boundary.

Other resolvers in scalars/node.py that walk nested lazy relationships (e.g., availability.partitions, materializations.backfills, metric_metadata.unit) should be audited for similar errors. The general rule is that any property reaching through a non-eager-loaded relationship is now an issue under the session-per-resolver pattern.

Test Plan

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 20, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 05b76de
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/69e6a58c1dce8d00089f5598

@shangyian shangyian changed the title The per resolver session pattern means that we need to return strawbe… Fix detached-instance crash on GraphQL dimensionLinks.foreignKeys Apr 20, 2026
@shangyian shangyian force-pushed the fix-gql-find-nodes branch from 6da63ad to fbd625d Compare April 20, 2026 16:57
@shangyian shangyian marked this pull request as ready for review April 20, 2026 20:40
@shangyian shangyian requested a review from jlhester April 20, 2026 20:40
default_value=link.default_value,
),
)
return links
Copy link
Copy Markdown
Collaborator

@jlhester jlhester Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should self.dimension_links be updated to be links at the end of the method here? What's the point of completely rebuilding each dimension link object?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up completely simplifying this ... the only thing that's needed is the pre-seeding of the node revision relationship

continue # hard-deleted or deactivated dimension node
set_committed_value(link, "node_revision", self)
links.append(
DimensionLink( # type: ignore[call-arg]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be fragile if DimensionLink is ever updated to include more fields

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes good point... this is actually unnecessary now that we're returning a DimensionLink ORM obj with node_revision pre-seeded so foreign_keys can resolve without a lazy load.

@shangyian shangyian merged commit 781d158 into DataJunction:main Apr 20, 2026
25 checks passed
@shangyian shangyian deleted the fix-gql-find-nodes branch April 20, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants