You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
When an xs:dateTime is restricted to a subset of the allowed lexical space with fixed number of fractional seconds digits, marshalling Python instances to XML ignores this restriction.
<?xml version="1.0" encoding="UTF-8"?>
<testelementxmlns="datetimetest"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="datetimetest file:<path to above xsd>"
>2019-11-29T15:30:16.100Z</testelement>
Converting from and to XML then gives 2019-11-29T15:30:16.1Z. This is in the canonical lexical space of the unrestricted dateTime type, but does not correspond to the above schema.
Similarly, when the original value is more precise than what the XSD restriction pattern indicates, e.g. 2019-11-29T15:30:16.100131Z, the generated XML will always be as precise as the original value (well, up to a maximum of six digits, as Python's datetime.datetime goes to microsecond accuracy).
Is there some way to work around this, or should I just tell our XSD modellers to stop restricting dateTimes in such a way?
Btw, I'm on pyxb 1.2.6, Python 3.6.7 and a Mac.
The text was updated successfully, but these errors were encountered:
@note: In PyXB, pattern constraints are ignored for any type with
Basically the value has already been converted to a Python dateTime instance at the point where the pattern constraint is checked. That means the original lexical representation has been discarded. So PyXB doesn't validate the document when it's parsed.
PyXB also doesn't attempt to generate lexical representations that are consistent with restrictions, since that's outside the scope of validation (and would be really really hard to do). So the generated representation isn't going to satisfy the restriction either.
It's possible there'd be a way to work around this with a customized binding class but it'd probably be painful.
@todo: On creating new instances of non-string simple types from
string representations, we could apply pattern constraints. That
would mean checking them prior to invoking the Factory method.
I'm not sure how that squares with you what said above, but if implemented it would make life a bit easier in these situations. But if this @todo is no longer on the roadmap, I think this issue can be closed.
Given #100 and the fact the @todo was introduced on 2009-09-06 I think we can say it's not on the roadmap. Thanks for using PyXB and for your report. I'll leave it open since it's legitimate and unresolved, but have marked it as unlikely to be worked.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When an
xs:dateTime
is restricted to a subset of the allowed lexical space with fixed number of fractional seconds digits, marshalling Python instances to XML ignores this restriction.For instance, with the following schema:
And the following XML:
Converting from and to XML then gives
2019-11-29T15:30:16.1Z
. This is in the canonical lexical space of the unrestricted dateTime type, but does not correspond to the above schema.Similarly, when the original value is more precise than what the XSD restriction pattern indicates, e.g.
2019-11-29T15:30:16.100131Z
, the generated XML will always be as precise as the original value (well, up to a maximum of six digits, as Python's datetime.datetime goes to microsecond accuracy).Is there some way to work around this, or should I just tell our XSD modellers to stop restricting dateTimes in such a way?
Btw, I'm on pyxb 1.2.6, Python 3.6.7 and a Mac.
The text was updated successfully, but these errors were encountered: