Skip to content

Maintain forward references when generating a recursive schema#883

Closed
SrirachaHorse wants to merge 1 commit intotefra:mainfrom
SrirachaHorse:fix-882
Closed

Maintain forward references when generating a recursive schema#883
SrirachaHorse wants to merge 1 commit intotefra:mainfrom
SrirachaHorse:fix-882

Conversation

@SrirachaHorse
Copy link
Contributor

@SrirachaHorse SrirachaHorse commented Dec 14, 2023

📒 Description

Ensures that compound fields in dataclasses maintain forward references for recursively defined types, even if postponed annotations are enabled.

Resolves #882

🔗 What I've Done

Adds an extra check to xsdata.formats.dataclass.filters.Filters.field_type_name() to ensure that the given attribute is not a circular reference, before stripping its surrounding " characters. If it is a circular reference, the type will retain its surrounding " characters.

💬 Comments

🛫 Checklist

@codecov
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c6a1c66) 99.89% compared to head (f19baa6) 99.89%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #883   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files         105      105           
  Lines        9311     9311           
  Branches     2080     2080           
=======================================
  Hits         9301     9301           
  Misses          3        3           
  Partials        7        7           

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

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

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

See analysis details on SonarCloud

@tefra
Copy link
Owner

tefra commented Dec 16, 2023

Thank you very much @SrirachaHorse for bringing this issue to my attention, your fix is a little extreme, I limited the effect to only the choice type annotations here #886

Nevertheless, thank you very much for this, I 've been working on and off to update the pydantic plugin to v2 and I couldn't troubleshoot why some cases were failing, I think that was the culprit but it wasn't very easy to debug in my current samples.

If you are working with a suite that demonstrates this issue, I would love to include it in the samples repo https://github.com/tefra/xsdata-samples

@tefra tefra closed this Dec 16, 2023
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.

Forward referencing when generating a recursive schema

2 participants