Skip to content

Fix KeyError when models_package is not set#1219

Open
jootten wants to merge 1 commit into
tefra:mainfrom
jootten:fix-binding-model-detection
Open

Fix KeyError when models_package is not set#1219
jootten wants to merge 1 commit into
tefra:mainfrom
jootten:fix-binding-model-detection

Conversation

@jootten
Copy link
Copy Markdown
Contributor

@jootten jootten commented Apr 21, 2026

📒 Description

Follow-up to #1144. That PR added an and clazz.__module__ in sys.modules guard to XmlContext.is_binding_model to prevent a KeyError, but placed it inside the branch that only runs when models_package is set. When no models_package is configured, is_binding_model short-circuits on not self.models_package and the guard is skipped.

I've encountered this bug for example with amd.HIPOptions from triton.

This PR restructures the predicate so the sys.modules guard applies in both cases.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.97%. Comparing base (00e6276) to head (44653fa).

Files with missing lines Patch % Lines
xsdata/formats/dataclass/context.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #1219      +/-   ##
===========================================
- Coverage   100.00%   99.97%   -0.03%     
===========================================
  Files          116      116              
  Lines         9376     9379       +3     
  Branches      1439     1440       +1     
===========================================
+ Hits          9376     9377       +1     
- Misses           0        1       +1     
- Partials         0        1       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jootten jootten force-pushed the fix-binding-model-detection branch from 75d02b2 to 368ec04 Compare April 21, 2026 09:41
tefra#1144 added a sys.modules check to avoid KeyError, but it was only
reached when models_package was configured. Without it, the original
KeyError still came back.

Move the check out so it runs in both cases.
@jootten jootten force-pushed the fix-binding-model-detection branch from 368ec04 to 44653fa Compare April 21, 2026 10:24
@jootten jootten changed the title Fix KeyError when models_package is not configured Fix KeyError when models_package is not set Apr 21, 2026
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant