Repository navigation
Rename a column named like a module used in its annotation (uuid, datetime, decimal) - #492
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Changes
Fixes #331 (closed as fixed, but it is back in 4.0.4 and master).
A table with a column named
uuidof type uuid generates models that fail at import:Inside the class body the attribute
uuidshadows theuuidmodule used in the annotation. The same happens for a column nameddatetimeordecimal, with the declarative and dataclass generators.Attribute names are made unique against
global_names, which only held thefrom x import ynames. The modules used in theMapped[]annotations were added later, while rendering.DeclarativeGenerator.collect_imports_for_modelnow renders the column python types while collecting imports, and the module imports are added toglobal_names, so such a column becomesuuid_ = mapped_column('uuid', ...), the same waymetadataandregistryare handled.Checklist
tests/) which would fail without your patch:test_column_named_like_annotation_moduleCHANGES.rst).pytest: 159 passed; the 6tests/test_cli.pyfailures here (FileNotFoundError, thesqlacodegenscript isn't on PATH in my venv) are the same without this change. Generated models for a Postgres table with auuidcolumn now import.