Failure to assign proper type in bindings

Help
2013-02-12
2013-03-06
  • David Meyer
    David Meyer
    2013-02-12

    I am trying to generate valid xml using pyxb and I am running into an issue. The schema that I am using has multiple elements. In one case I declare a complex type, called Registration inside a schema named Registration.xsd. This registration type has a sequence of elements. Then I declare an element RegistrationRequest, which has an element Register of type Registration.

    When I am trying to generate a RegistrationRequest object in python, I call:

    regreq = Registration.RegistrationRequest()

    But, when I try to assign one of the elements within the regreq.Register element I get an error. The error is that

    NoneType object has no attribute 'Client'

    I tried looking at the pyxb.BIND section but I got a much longer error dealing with an UnboundLocalError, even though I have RequireValidWhenGenerating set to False.

    On a slightly related note, when I try to write an xml from this instance of a RegistrationRequest the elements are not written in the same order in which the schema says they should appear. I was looking into contentInfluencesGeneration flag, but that didn't seem to help. Is there something that I am missing?

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-02-12

    UnboundLocalError is a Python exception and is unlikely to be directly due to PyXB, though you'd have to provide the stack trace to be sure.

    The AttributeError may occur if you have not assigned any instances to the component elements of regreq.  When you create an empty instance of a complex type with element content, PyXB does not recursively create those elements for you; thus if you did:

      regreq.Something.Client = SomethingElse
    

    this would fail unless you had assigned an instance of the appropriate complex type to regreq.Something.

    Review the material at http://pyxb.sourceforge.net/userref_usebind.html#creating-instances-in-python-code.

     
  • David Meyer
    David Meyer
    2013-02-12

    I am now setting a value as follows:

    regreq.Register = Registration.Registration()
    regreq.Register.Client = ''

    but I am getting an logical error when I invoke toxml()

    LogicError: toDOM with unrecognized value type <class 'pyxb.binding.content._PluralBinding'>:

    Is this because of something in my schema?

    As for the problem with the order of generated elements in the toxml command, is there a different setting or place I should look?

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-02-12

    Re the LogicError: I can't tell from the information you've provided.  That might happen if you did regreq.Something.toXML() and the Something element can occur multiple times so is represented as a list (or PluralBinding).

    I didn't notice the question about generated elements.  PyXB does not necessarily preserve original document order, but the output should be valid relative to the schema.  Issue #184 https://sourceforge.net/apps/trac/pyxb/ticket/184 fixed one problem with that but the change hasn't been incorporated into a release yet, and it should only have affected cases where complex type extension was used.  You could try checking out the branch "next" of the git repository and using that version.

     
  • David Meyer
    David Meyer
    2013-02-12

    Thanks for the verification that I wasn't crazy about the order of xml generation, I will see if I can get this to work correctly in my code.

    As for the LogicError I have provided the full report here:

    Traceback (most recent call last):
      File "C:\130212_TortoiseCheckout\AttemptStomp.py", line 67, in <module>
        print('The xml to be used for registration \n %s' % regreq.toxml("utf-8"))
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 544, in toxml
        dom = self.toDOM(bds)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 524, in toDOM
        self._toDOM_csc(bds, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1081, in toDOM
        value._toDOM_csc(dom_support, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1086, in toDOM
        raise pyxb.LogicError('toDOM with unrecognized value type %s: %s' % (type(value), value))
    LogicError: toDOM with unrecognized value type <type 'type'>: <type 'property'>

    The parameter regreq was generated from an xsd as follows:

    regreq = Registration.RegistrationRequest()
    regreq.Register = Registration.Registration()
    regreq.Register.Client = ''

    I just need an element within the regreq xml named Register. Inside Register is a Client field that is empty. When I execute regreq.toxml() I get that error above. Did I provide enough info to help track down the issue?

     
  • David Meyer
    David Meyer
    2013-02-12

    Sorry, a correction to the error report. I had tried a couple of workarounds myself that didn't work and generated different errors. Again, ignore the previous error report and see this one:

    Traceback (most recent call last):
      File "C:\130212_TortoiseCheckout\AttemptStomp.py", line 67, in <module>
        print('The xml to be used for registration \n %s' % regreq.toxml("utf-8"))
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 544, in toxml
        dom = self.toDOM(bds)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 524, in toDOM
        self._toDOM_csc(bds, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1081, in toDOM
        value._toDOM_csc(dom_support, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1086, in toDOM
        raise pyxb.LogicError('toDOM with unrecognized value type %s: %s' % (type(value), value))
    LogicError: toDOM with unrecognized value type <class 'pyxb.binding.content._PluralBinding'>:

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-02-12

    What's going wrong is that the regreq is not valid.  Without seeing the schema I can't tell why it's not valid; this exception doesn't match the one you originally described (that got a PluralBinding, this somehow is getting a property).  You could try things like:

    reg2 = Registration.Registration(Client='')
    regreq.Register.append(reg2)
    

    If you can clearly demonstrate a problem in PyXB I'll work to fix it, but at the moment the problem seems to be with how you're using it or with the schema, and I can't really fix that for you.  You're best off building things up from leaf elements that you validate first.

     
  • David Meyer
    David Meyer
    2013-02-12

    See my previous post about the wrong error message. I did get a _PluralBinding issue, but I had tried to work around it by assigning a property. I have to admit that I am mostly fiddling in the dark here. I am certain that the issue is with my implementation, but I can't seem to figure out why it isn't working. The error was:

    Traceback (most recent call last):
      File "C:\Users\meyerd_user\Documents\AxiosWork\130212_TortoiseCheckout\AttemptStomp.py", line 67, in <module>
        print('The xml to be used for registration \n %s' % regreq.toxml("utf-8"))
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 544, in toxml
        dom = self.toDOM(bds)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 524, in toDOM
        self._toDOM_csc(bds, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1081, in toDOM
        value._toDOM_csc(dom_support, element)
      File "C:\Python27\lib\site-packages\pyxb\binding\basis.py", line 2547, in _toDOM_csc
        content.elementDeclaration.toDOM(dom_support, parent, content.value)
      File "C:\Python27\lib\site-packages\pyxb\binding\content.py", line 1086, in toDOM
        raise pyxb.LogicError('toDOM with unrecognized value type %s: %s' % (type(value), value))
    LogicError: toDOM with unrecognized value type <class 'pyxb.binding.content._PluralBinding'>:

     

  • Anonymous
    2013-02-28

    I got the error

    pyxb.exceptions_.LogicError: toDOM with unrecognized value type <class 'pyxb.binding.content._PluralBinding'>:

    when calling .toxml() when also using

    pyxb.RequireValidWhenGenerating(False)

    Setting it to True removed the error and correctly rendered the XML.