You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "stevedlawrence (via GitHub)" <gi...@apache.org> on 2024/03/15 12:33:45 UTC
[PR] Add ability to support or ignore restrictions not allowed by DFDL [daffodil]
stevedlawrence opened a new pull request, #1185:
URL: https://github.com/apache/daffodil/pull/1185
A new tunable call invalidRestrictionPolicy is added to control how Daffodil handles restrictions that are not allowed by DFDL. This has values of "error", "ignore", "validate, which tell Daffodil to SDE (current behavior), allow but do not use the restriction for validation, or allow and use it for validation, respecitvely.
This tunable currently only affects the xs:pattern restriction on non-string types. This allows extra validation capabilities using just XML Schema that would otherwise require a different validation mechanism like schematron.
Note that Daffodil's pattern validation implementation already works for non-string types, so relatively few changes are needed to support the "validation" option. The only real change is to move the logic related to this new tunable into the Restriction class, since the patternValues variable in that class is what the SimpleTypeRuntimeData uses for validation.
DAFFODIL-2877
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add ability to support or ignore restrictions not allowed by DFDL [daffodil]
Posted by "stevedlawrence (via GitHub)" <gi...@apache.org>.
stevedlawrence commented on code in PR #1185:
URL: https://github.com/apache/daffodil/pull/1185#discussion_r1526540195
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyError"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Pattern restriction</tdml:error>
+ <tdml:error>string</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyIgnore_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyIgnore"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyValidate_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyValidate"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors>
+ <tdml:error>failed facet checks</tdml:error>
+ <tdml:error>pattern</tdml:error>
+ <tdml:error>.*[05]</tdml:error>
+ </tdml:validationErrors>
Review Comment:
Mentioned above, but validation errors are ignored if there is no `<tdml:validationErrors>` element, so with those lines removed this test would still pass but would not verify that validation occurred.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add ability to support or ignore restrictions not allowed by DFDL [daffodil]
Posted by "tuxji (via GitHub)" <gi...@apache.org>.
tuxji commented on code in PR #1185:
URL: https://github.com/apache/daffodil/pull/1185#discussion_r1526450719
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
Review Comment:
Just a note for reviewers that the `root` attribute is redundant (and can be omitted) if the `model` schema has only one root element or you want to use its first root element.
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyError"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Pattern restriction</tdml:error>
+ <tdml:error>string</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyIgnore_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyIgnore"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
Review Comment:
Very interesting. I have a mental picture of how TDML tests work expecting that you have to match the exit status, tdml errors, and tdml validation errors correctly for the test to pass and the test would fail if it produced validation errors without a match expecting them. If my mental picture is wrong and we really need line 874, please change the comment to `make sure there are no validation errors` to be clear that the line is needed to complete the test. Otherwise, please leave the comment `there should be no validation errors` but strip out `<tdml:validationErrors \>` in the same line if it's not needed.
Also, if you changed the config to validate the pattern and removed line 874 checking there are no validation errors, would the "daffodil test" command print the validation errors in its test output, or would you never know that the test passed despite producing validation errors?
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyError"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Pattern restriction</tdml:error>
+ <tdml:error>string</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyIgnore_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyIgnore"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyValidate_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyValidate"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors>
+ <tdml:error>failed facet checks</tdml:error>
+ <tdml:error>pattern</tdml:error>
+ <tdml:error>.*[05]</tdml:error>
+ </tdml:validationErrors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyValidate_02" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyValidate"
+ validation="limited">
+ <tdml:document>200</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>200</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
Review Comment:
Same thoughts here.
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyError"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Pattern restriction</tdml:error>
+ <tdml:error>string</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyIgnore_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyIgnore"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyValidate_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyValidate"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors>
+ <tdml:error>failed facet checks</tdml:error>
+ <tdml:error>pattern</tdml:error>
+ <tdml:error>.*[05]</tdml:error>
+ </tdml:validationErrors>
Review Comment:
Actually, if you need to double check whether it is necessary to match validation errors, this test is easier to edit than any of the other tests. The only change you need is to comment out lines 888 to 892 and check if the test still passes (and whether you see any of the validation messages in the test's output).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add ability to support or ignore restrictions not allowed by DFDL [daffodil]
Posted by "stevedlawrence (via GitHub)" <gi...@apache.org>.
stevedlawrence commented on code in PR #1185:
URL: https://github.com/apache/daffodil/pull/1185#discussion_r1526537891
##########
daffodil-test/src/test/resources/org/apache/daffodil/section00/general/tunables.tdml:
##########
@@ -811,4 +832,78 @@
</tdml:unparserTestCase>
+ <tdml:defineSchema name="intPatternRestriction">
+ <xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <xs:element name="int">
+ <xs:simpleType>
+ <xs:restriction base="xs:int">
+ <xs:pattern value=".*[05]" /> <!-- must be a multiple of 5 -->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyError_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyError"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>Pattern restriction</tdml:error>
+ <tdml:error>string</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase
+ name="invalidRestrictionPolicyIgnore_01" root="int"
+ model="intPatternRestriction"
+ config="cfg_invalidRestrictionPolicyIgnore"
+ validation="limited">
+ <tdml:document>201</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:int>201</ex:int>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:validationErrors /> <!-- there should be no validation errors -->
Review Comment:
If a test case does not have a `<tdml:validationErrors>` element, then validation errors created by the test are ignored. Validation errors created by the test have no affect on the success/failure of the test.
If a test case has a `<tdml:validationErrors>` element and that element has `<tdml:error>` children, then the test *must* create validation errors and each of the `<tdml:error>` strings *must* appear in those messages. If any do not, the test fails.
If a test case has a `<tdml:validationErrors>` element but that element does not have children, then the test case *must not* create validation errors. If there are any validation errors the test fails.
In each of these cases, the infoset must still match the expected infoset or the test is a failure, regardless of any validation errors.
So this test technically doesn't need an empty `<tdml:validationErrors />` element to pass. But it does ensure that we are correctly ignoring the pattern restriction and not trying to validate anything. Without it, things could be broken and we could still be validating but not know it (in fact, my first change was broken and wasn't ignoring things and this test caught it).
I'll update to the comment as suggested.
> Also, if you changed the config to validate the pattern and removed line 874 checking there are no validation errors, would the "daffodil test" command print the validation errors in its test output, or would you never know that the test passed despite producing validation errors?
I believe the behavior of "sbt test" and the CLI "daffodil test" is to hide all output unless something fails. So if there were validation errors but no `<tdml:validationErrors />` element in the test case, then the validation error woudl be ignored, the test would be considered a success, and you would never know. I think enabling verbose test output does output the validation errors even on success, so it's not completely hidden, but you do need to do something special to see it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add ability to support or ignore restrictions not allowed by DFDL [daffodil]
Posted by "stevedlawrence (via GitHub)" <gi...@apache.org>.
stevedlawrence merged PR #1185:
URL: https://github.com/apache/daffodil/pull/1185
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org