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

Remove dataclasses from xsi_cache with unsupported types #796

Merged
merged 1 commit into from
Jun 5, 2023
Merged

Conversation

tefra
Copy link
Owner

@tefra tefra commented Jun 4, 2023

📒 Description

xsdata scans all modules for supported models (dataclasses). If the model includes unsupported types these are excluded but it seems now there is trend people are defining dataclasses like these

if TYPE_CHECKING:
    from typing_extensions import Literal

    _CaptureMethod = Literal["fd", "sys", "no", "tee-sys"]


class Foo:
    a: "_CaptureMethod"

Which raises a NameError when xsdata tries to analyze the typing annotation, since it's not defined 😮‍💨

A few versions back, I added a patch for pytest which seems to be doing that a lot, but the patch was a bit flaky because it assumed people would always override a class __module__ property with something that returns a string, which surprisingly is not always the case 🤦

Resolves #795

🔗 What I've Done

  • Add a more secure patch, which will catch undefined types like the unsupported types and additionally remove these classes from xsi cache on the fly, to avoid re-evaluating the same class more than once.

💬 Comments

A place to write any comments to the reviewer.

🛫 Checklist

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Jun 4, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4a02fa6) 99.96% compared to head (c1626f4) 99.96%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #796   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files         104      104           
  Lines        9204     9208    +4     
  Branches     2060     2060           
=======================================
+ Hits         9201     9205    +4     
  Partials        3        3           
Impacted Files Coverage Δ
xsdata/formats/dataclass/models/builders.py 100.00% <ø> (ø)
xsdata/formats/dataclass/context.py 100.00% <100.00%> (ø)

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

@tefra tefra merged commit a768eef into master Jun 5, 2023
@tefra tefra deleted the fix-795 branch June 5, 2023 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError during build_xsi_cache for _ObjectPropertyMethods
1 participant