-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
XsData ignores some choice elements #737
Comments
I did some digging, and my results are probably not the final results. My findings are that at least one of the elements within the xs:choice element must have maxOccurs="unbounded". Otherwise the choice element is ignored. The other problem I realised is that the 'choices' tag in the metadata of a dataclass does not have any of the options indicated there. E.g. the maxOccurs="unbounded" is not obvious, and if I include a minOccurs, that won't appear there neither. Possibly other options are also omitted. |
Examples:
Results:
|
I can't remember why this condition was added to be honest, it looks like a remnant from the very first compound fields implementation. https://github.com/tefra/xsdata/blob/master/xsdata/codegen/handlers/create_compound_fields.py#L32 I 'll check again and remove it. Thank you @martinwiesmann for your awesome analysis |
Great, thanks. Great job in finding the problematic line so quickly. Unfortunately, there remains another problem: If for some reason there is actually a 'max_occurs=unbounded' as a restriction to a choice-element (which is the case in our project), then this is not reflected in the python dataclass, see above class 'GenericKVParam' choice-element 'Files'. I haven't checked any other restrictions (e.g. minInclusive etc), but it would be nice to have this information also in the dataclass. Thanks for your great work. |
It seems that most restrictions are in the dataclass, but minOccurs and maxOccurs are not. See the example:
becomes:
|
Hi @martinwiesmann the fix for the first issue is on master, give it a try and let me know how it works for you. This one was tough to crack but I am happy that you brought this up, it involved fixing some early patches early on to make things to just work. Thank you for reporting! I split the second one here #748. |
I just tested this with my schema and it works great. <xs:choice maxOccurs="1"> now generates choices correctly in my models. Thanks! |
Thank you @tefra |
XsData seems to have a problem in recognising some choice elements.
I think this is a bug in XsData, since PyXB used to pick up on all choice elements.
But maybe there is a workaround to this problem, that I could apply. But I haven't found it yet.
For example, a xsd like this:
produces this class:
This class definition does not include any hint that only one of these elements are allowed. The correct class should look more like this:
This xsd however produces a correct dataclass
produces this class:
which is correct.
Another example that fails:
Xsd:
produces this class:
which does not include the choice part.
The text was updated successfully, but these errors were encountered: