Open evanunderscore opened 7 years ago
Nothing is obvious to me. I'll take a look when I'm next working PyXB.
The problem appears to be based on which order things are in orderedContent()
. For example, if in my example script you replace m = element(a='a', b='b')
with m = element(); m.b = 'b'; m.a = 'a'
, the intermittently failing examples will fail every time.
I've also noticed that when using Python 3.6, all intermittent failures disappear. This almost guarantees the problem is related to dict iteration order (since dicts in Python 3.6 retain their ordering). What's interesting is that both m = element(a='a', b='b')
and m = element(b='b', a='a')
give you the same orderedContent()
with a
before b
, which seems to mean something is being done to put the elements in the correct order and for Python < 3.6 it's being lost somewhere in the internals.
I've now come to realize that what I'm really asking for is probably a lot more complicated than I previously thought, so even if this problem were fixed I'd need to rethink my approach.
Background: I have an element which can contain multiple other elements, repeated and in any order, and I need the ordering of these elements to be maintained. I saw a comment from you elsewhere saying that there was an example of how to enable this in
pyxb.bundles.common.xhtml1
. I adapted this for my own bindings which solved the ordering problem, but also produced intermittent failures when generating unrelated documents.The failure seems to have something to do with the hash seed which I believe affects things like the iteration order for dicts. The intermittent failure occurs by default in Python 3 but only occurs with the
-R
interpreter option in Python 2. Fixing the hash seed via thePYTHONHASHSEED
environment variable produces consistent results.Sample schema (foo.xsd):
The first element
foo
can contain any number ofbar
orbaz
elements, and their ordering is what I'm attempting to preserve. The other two elementsminOccurs_1
andminOccurs_0
are unrelated elements that will sometimes fail to generate documents.Compile bindings:
Code to reproduce (foo.py):
The variables at the top of the script are intended to be adjusted to demonstrate different results.
When setting the config options as for xhtml, regardless of whether
optional
is True or False, the example will produceInvalidPreferredElementContentError
about half the time.If not using
_setInvalidElementInContent
, the example works consistently for the non-optional element.However with the optional element, it produces
UnprocessedElementContentError
about half the time.Any insight you have would be greatly appreciated.