Skip to content
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

problem when xml has empty values and xsd has asserts checking on theses values on xmlschema11 #356

Closed
ugzas opened this issue Jul 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@ugzas
Copy link

ugzas commented Jul 13, 2023

how to reproduce: xml has empty prtctn_prvdr_instttnl_sctr:

<data>
    <row>
      <entty_cntry>SE</entty_cntry>
      <typ_accntng_itm>45</typ_accntng_itm>
      <typ_instrmnt>1</typ_instrmnt>
      <crrncy_dnmntn>GBP</crrncy_dnmntn>
      <rsdl_mtrty>20</rsdl_mtrty>
      <cntrprty_instttnl_sctr>S541</cntrprty_instttnl_sctr>
      <cntrprty_cntry>DKK</cntrprty_cntry>
      <accrd_intrst>0</accrd_intrst>
      <prtctn_prvdr_instttnl_sctr></prtctn_prvdr_instttnl_sctr>
      <prtctn_prvdr_cntry>value</prtctn_prvdr_cntry>
      <prtctn_allctd_vl_prdntl_prps>0</prtctn_allctd_vl_prdntl_prps>
    </row>
  </data>

xsd has such asserts

<xs:assert test="if (rb:prtctn_allctd_vl_prdntl_prps != '') then (rb:prtctn_prvdr_instttnl_sctr != '') else true()"/> <!-- CBS_CT_16 -->
<xs:assert test="if (rb:prtctn_prvdr_instttnl_sctr != '') then (rb:prtctn_allctd_vl_prdntl_prps != '') else true()"/> <!-- CBS_CT_16 -->
<xs:assert test="if (rb:prtctn_prvdr_cntry = rb:cntrprty_cntry) then (rb:prtctn_prvdr_instttnl_sctr != rb:cntrprty_instttnl_sctr) else true()"/>

and with such code i cannot go in loop through these errors

import xmlschema

add_error = []
with open('iris_cbs.xml', encoding='utf-8') as xml_file:
    xml_string = xml_file.read()
    schema = xmlschema.XMLSchema11('cbs.xsd', validation="lax")
    validation_error_iterator = schema.iter_errors(xml_string)
    print(enumerate(validation_error_iterator))

    for idx, validation_error in enumerate(validation_error_iterator, start=1):
        add_error = f'Error on: {validation_error}'
        if idx >= 100:
            print(f'Reached XML error count limit: [{idx}] items')
            add_error(f'Reached XML error count limit: [{idx}] items')
            break
        print(add_error)**

getting error
AttributeError: 'NoneType' object has no attribute 'strip'

@ugzas
Copy link
Author

ugzas commented Jul 13, 2023

full errror:

File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\schemas.py", line 1812, in iter_errors
for result in xsd_element.iter_decode(elem, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\elements.py", line 752, in iter_decode
for result in content_decoder.iter_decode(obj, validation, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\groups.py", line 1022, in iter_decode
for result in xsd_element.iter_decode(child, validation, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\elements.py", line 752, in iter_decode
for result in content_decoder.iter_decode(obj, validation, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\groups.py", line 1022, in iter_decode
for result in xsd_element.iter_decode(child, validation, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\elements.py", line 749, in iter_decode
for error in assertion(obj, **kwargs):
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\assertions.py", line 144, in call
if not self.token.evaluate(context):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath2_xpath2_operators.py", line 140, in evaluate_if_expression
return self[1].evaluate(context)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath2_xpath2_operators.py", line 484, in evaluate_parenthesized_expression
return self[0].evaluate(context) if self else []
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath1_xpath1_operators.py", line 482, in evaluate_comparison_operators
return any(op(x1, x2) for x1, x2 in self.iter_comparison_data(context))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath1_xpath1_operators.py", line 482, in
return any(op(x1, x2) for x1, x2 in self.iter_comparison_data(context))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath_tokens.py", line 523, in iter_comparison_data
for values in product(left_values, right_values):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath_tokens.py", line 421, in atomization
value = item.typed_value
^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\elementpath\xpath_nodes.py", line 543, in typed_value
value = self.xsd_type.decode(self.elem.text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\xsdbase.py", line 968, in decode
for result in self.iter_decode(obj, validation, **kwargs): # pragma: no cover
File "C:\Users\s2803f\AppData\Local\Programs\Python\Python311\Lib\site-packages\xmlschema\validators\simple_types.py", line 1106, in iter_decode
if ' ' not in obj.strip():
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'strip'

@brunato
Copy link
Member

brunato commented Jul 22, 2023

Hi,
could you provide the 'cbs.xsd' schema (or a link to it)?

Thank you

@ugzas
Copy link
Author

ugzas commented Jul 24, 2023

adding link https://www.riksbank.se/en-gb/statistics/reporting-of-international-bank-statistics-iris/for-reporting-agents/

brunato added a commit that referenced this issue Jul 26, 2023
  - Fix for issue #356 requires a new bugfix release of
    elementpath package (maybe v4.1.5)
@brunato
Copy link
Member

brunato commented Jul 28, 2023

Hi, the releases v2.4.0 of xmlschema and v4.1.5 of elementpath should fix this problem.

@brunato brunato added the bug Something isn't working label Aug 30, 2023
@brunato brunato closed this as completed Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants