tefra / xsdata

Naive XML & JSON Bindings for python
https://xsdata.readthedocs.io
MIT License
310 stars 56 forks source link

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

Closed tefra closed 2 months ago

tefra commented 2 months ago

📒 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

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 2 months ago

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