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

🐛Fixes TypeError: issubclass() arg 1 must be a class while building BaseCustomSettings classes #5253

Merged
merged 10 commits into from
Jan 19, 2024

Conversation

pcrespov
Copy link
Member

@pcrespov pcrespov commented Jan 19, 2024

What do these changes do?

Some configurations with BaseCustomSettings subclasses raised TypeError: issubclass() arg 1 must be a class.

This is raised by issubclass when using pydantic subclasses (e.g. BaseCustomSettings inherits from BaseSettings) in combination with "composed" types as dict[str, str].

>>> issubclass(dict[str, str], dict)
False
 >> issubclass(dict[str, str], BaseSettings)
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/home/crespo/.pyenv/versions/3.10.13/lib/python3.10/abc.py", line 123, in __subclasscheck__
        return _abc_subclasscheck(cls, subclass)
    TypeError: issubclass() arg 1 must be a class

Some more information and references to pydantic issues are provided in the code's tests

Related issue/s

How to test

Tests that reproduces the bug in

cd packages/settings-library
pytest -vv -k test_issubclass_type_error_with_pydantic_models

Dev Checklist

DevOps Checklist

@pcrespov pcrespov self-assigned this Jan 19, 2024
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (12fd547) 87.6% compared to head (40b6832) 87.1%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5253      +/-   ##
=========================================
- Coverage    87.6%   87.1%    -0.5%     
=========================================
  Files         930    1302     +372     
  Lines       38953   53229   +14276     
  Branches      775    1168     +393     
=========================================
+ Hits        34134   46409   +12275     
- Misses       4650    6570    +1920     
- Partials      169     250      +81     
Flag Coverage Δ
integrationtests 63.6% <ø> (-1.5%) ⬇️
unittests 85.1% <57.1%> (-0.5%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ages/settings-library/src/settings_library/base.py 89.2% <57.1%> (ø)

... and 395 files with indirect coverage changes

@pcrespov pcrespov force-pushed the fix/base-custom-settings branch from 9155e09 to c378b9a Compare January 19, 2024 14:04
@pcrespov pcrespov marked this pull request as ready for review January 19, 2024 14:12
@pcrespov pcrespov requested a review from sanderegg as a code owner January 19, 2024 14:12
@pcrespov pcrespov changed the title 🐛Fix/base custom settings 🐛Fixes TypeError: issubclass() arg 1 must be a class while building BaseCustomSettings classes Jan 19, 2024
Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

🎉 thanks a lot!

@pcrespov pcrespov added this to the This is Sparta! milestone Jan 19, 2024
@pcrespov pcrespov enabled auto-merge (squash) January 19, 2024 14:19
Copy link
Contributor

@bisgaard-itis bisgaard-itis left a comment

Choose a reason for hiding this comment

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

Cool! Thanks!

@pcrespov pcrespov force-pushed the fix/base-custom-settings branch from c378b9a to 8b09992 Compare January 19, 2024 16:18
Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

thanks. not sure I get the point with the EnvVarsList becoming an iterable though. but all good.

@pcrespov pcrespov force-pushed the fix/base-custom-settings branch from 8b09992 to 40b6832 Compare January 19, 2024 17:32
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@pcrespov pcrespov merged commit 42d7630 into ITISFoundation:master Jan 19, 2024
54 checks passed
@pcrespov pcrespov deleted the fix/base-custom-settings branch January 22, 2024 09:36
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request Feb 14, 2024
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants