Correct imports and improve generation logic in SQLModelGenerator#352
Closed
touale wants to merge 4 commits intoagronholm:masterfrom
Closed
Correct imports and improve generation logic in SQLModelGenerator#352touale wants to merge 4 commits intoagronholm:masterfrom
SQLModelGenerator#352touale wants to merge 4 commits intoagronholm:masterfrom
Conversation
This reverts commit 2e8ff91.
Collaborator
|
@agronholm I believe #358 also takes care of this PR, at least the mapped_column (and albit in a cleaner fashion). the CHAR part, is still an issue I guess. Once the former is merged, we can revisit this one |
Author
|
In fact, the changes I made were aimed at quickly and efficiently resolving my production and development issues in a short period of time |
Owner
|
This is a quick and dirty patch I will not accept. @sheinbergon your PR is the way to go. What in particular I don't like here is that the superclass is required to know about the subclass which is bad design. |
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.
In fact, I found that there are some problems in the code generated by
sqlacodegenforsqlmodel, which is manifested in the introduction of redundant classCHARand themapped_columndoes not been import. The following is a detailed description of the problem:(1) When encountering
CHAR(36)andCHAR(36, 'utf8mb4_general_ci'),sqlacodegenwill repeatedly import from different sourcesThe adjustment I made was to focus on sorted and high-priority imports, and to make a warn about duplicate imports.
for example:
In fact, "from sqlalchemy import CHAR" supports general projects of multiple databases, while "from sqlalchemy.dialects.mysql import CHAR" is specifically for MySQL projects. If you project requires cross-database compatibility or you are not sure about the target database type, it is safer to use "sqlalchemy.CHAR".
(2)
sqlmodeldoes not supportmapped_columnin the latest release(https://github.com/fastapi/sqlmodel/releases/tag/0.0.22), although someone has proposed a PR (fastapi/sqlmodel#1143), soColumnshould be used for the generation of sqlmodels for the time being