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: Avoid using not-threadsafe arnings.catch_warning #1042

Merged
merged 1 commit into from
May 19, 2024
Merged

fix: Avoid using not-threadsafe arnings.catch_warning #1042

merged 1 commit into from
May 19, 2024

Conversation

tefra
Copy link
Owner

@tefra tefra commented May 19, 2024

📒 Description

warnings.catch_warnings is not threadsafe. The main converter entry point raises warnings when a value can't be converted to the target types. It's up to the parsers to catch that warning per case and either raise ParserError or ignore them completely.

When we are parsing unions of classes, we intentional trap those warnings in order to find the best candidate, but since catch_warnings is not thread safe, confusing warnings are logged 🤦

Move the logic to convert warnings to exception from the parsers to the parser utils and avoid using the catch_warnings altogether.

Resolves #1041

🔗 What I've Done

Write a description of the steps taken to resolve the issue

💬 Comments

A place to write any comments to the reviewer.

🛫 Checklist

Copy link

codecov bot commented May 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (c544fbd) to head (346afc1).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1042   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          115       115           
  Lines         9270      9254   -16     
  Branches      2191      2187    -4     
=========================================
- Hits          9270      9254   -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented May 19, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarCloud

@tefra tefra merged commit ff5e759 into main May 19, 2024
15 checks passed
@tefra tefra deleted the fix-1041 branch May 19, 2024 12:31
skinkie pushed a commit to skinkie/xsdata that referenced this pull request Jun 18, 2024
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.

Simultaneous parsing sometimes causes "ConverterWarning: Failed to convert value"
1 participant