Repository navigation
Load reference table model before creating a reference table - #57
Merged
Merged
Conversation
create_table compiled the new table's DDL without ensuring the target table's model was registered in the in-process Base.metadata, so the string ForeignKey failed with NoReferencedTableError whenever the worker had not already used the target table. Load the target model first, and add a regression test with the target absent from the metadata. Fixes #56 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56.
create_tablecompiled the new table's DDL without making sure the target table's model was registered in the process-localBase.metadata. The reference column'sForeignKey("<target>.id")is a string resolved against that metadata, so creation failed withNoReferencedTableErrorwhenever the serving worker had not already used the target table. That is why it appeared intermittent across uwsgi workers.Fix: if the target is not in
Base.metadata.tables, load its model via_get_model_from_table_namebefore building the new model. This checks the metadata directly rather thancached_table(), which can be out of step with it.Test:
test_create_reference_table_cold_metadataremoves the target from the metadata and cache before creating the reference table. It fails without the fix with the same error as the issue, and passes with it. Full suite: 57 passed against PostGIS.Not addressed:
Base.metadatais keyed by table name only, so same-named tables in different aligned volumes can shadow each other (noted in the issue as a separate problem).🤖 Generated with Claude Code