Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve field type translation #44

Merged
merged 2 commits into from
Oct 13, 2022
Merged

Conversation

iron3oxide
Copy link
Contributor

Every subclass of the listed basic types is assumed to be meant to be translated to the corresponding SQLAlchemy types. Adds support for the Boolean, Date and DateTime types, fixes an issue where e.g. ConstrainedInt would be translated to JSON type, see #43 .

Since this changes the database type for some python types, it might break code or lead to unexpected results when regenerating tables that were first created before this change.

Every subclass of the listed basic types is assumed to be meant to be translated to the corresponding SQLAlchemy types.  Adds support for the Boolean, Date and DateTime types, fixes an issue where e.g. ConstrainedInt would be translated to JSON type.

Since this changes the database type for some python types, it might break code or lead to unexpected results when regenerating tables that were first created before this change.
@codecov-commenter
Copy link

Codecov Report

Base: 100.00% // Head: 99.43% // Decreases project coverage by -0.56% ⚠️

Coverage data is based on head (7070903) compared to base (28f94d6).
Patch coverage: 75.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##              main      #44      +/-   ##
===========================================
- Coverage   100.00%   99.43%   -0.57%     
===========================================
  Files           20       20              
  Lines          702      709       +7     
===========================================
+ Hits           702      705       +3     
- Misses           0        4       +4     
Impacted Files Coverage Δ
ormdantic/generator/_table.py 94.02% <75.00%> (-5.98%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@iron3oxide
Copy link
Contributor Author

Haven't been able to rewrite the tests yet, sorry for that. A little explanation why I chose to use issubclass() nearly everywhere:

  1. If done correctly (keeping some pitfalls like bool being a subclass of int in mind), this should catch non-pydantic types as well
  2. If pydantic changes its API with v2, e.g. implementing the CurrentDate type (planned) or renames/restructures/drops something like ConstrainedStr (not planned, just an example), everything should continue to work fine.

@yezz123 yezz123 linked an issue Oct 13, 2022 that may be closed by this pull request
@yezz123 yezz123 added bug Something isn't working enhancement New feature or request labels Oct 13, 2022
Copy link
Owner

@yezz123 yezz123 left a comment

Choose a reason for hiding this comment

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

Amazing work @iron3oxide 🚀 ! I fix the Linting issue and I add some tests for both the Bool case and the Date/DateTime case it looks good overall 👍🏻

@yezz123 yezz123 merged commit 6635cb7 into yezz123:main Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some fields are translated as JSON fields even though they shouldn't be
3 participants