Skip to content

Fix KeyError when models_package is not set - #1219

Merged
tefra merged 1 commit into
tefra:mainfrom
jootten:fix-binding-model-detection
Jul 18, 2026
Merged

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

Conversation

@jootten

@jootten jootten commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

📒 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

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

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

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         9390     9393       +3     
  Branches      1443     1444       +1     
===========================================
+ Hits          9390     9391       +1     
- Misses           0        1       +1     
- Partials         0        1       +1     

☔ View full report in Codecov by Harness.
📢 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 2 times, most recently 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

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.
@tefra
tefra force-pushed the fix-binding-model-detection branch from 44653fa to fdd06b6 Compare July 10, 2026 04:20
@sonarqubecloud

Copy link
Copy Markdown

@jootten

jootten commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Are any further modifications required @tefra?

@tefra
tefra merged commit 1fda878 into tefra:main Jul 18, 2026
12 of 14 checks passed
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.

2 participants