Skip to content
This repository was archived by the owner on Apr 29, 2023. It is now read-only.

UnboundElementError when trying to subclass #124

@bavovanachte

Description

@bavovanachte

I've made a working example of a ReqIf XML output with just the classes generated by pyxb.

Now, I wanted to subclass some of these classes to hide some of the pyxb.BIND() function calls (and add more functionality), but ran into some issues when trying to call a.toxml() later on.

Below is the way I've defined the subclass. I think I did it the same way as described here, but it gives me the following error:

Traceback (most recent call last):
  File "ReqIF.py", line 95, in <module>
    print(a.toxml());
  File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 560, in toxml
    dom = self.toDOM(bds, element_name=element_name)
  File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 528, in toDOM
    raise pyxb.UnboundElementError(self)
pyxb.exceptions_.UnboundElementError: Instance of type {http://www.omg.org/spec/ReqIF/20110401/reqif.xsd}REQ-IF has no bound element for start tag

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ReqIF.py", line 97, in <module>
    print(e.details())
AttributeError: 'UnboundElementError' object has no attribute 'details'

The code:

class REQ_IF_x(REQ_IF_):
    def __init__(self):
        super().__init__(
            THE_HEADER=pyxb.BIND(),
            CORE_CONTENT=pyxb.BIND(),
            TOOL_EXTENSIONS=pyxb.BIND(),
        )

REQ_IF_._SetSupersedingClass(REQ_IF_x)

# Construct the header
a = REQ_IF_x()
header = REQ_IF_HEADER(
    IDENTIFIER = "abcd",
    COMMENT = "abcd",
    CREATION_TIME = dateTime.today(),
    REPOSITORY_ID = "",
    REQ_IF_TOOL_ID = "",
    REQ_IF_VERSION = "1.0",
    SOURCE_TOOL_ID = "",
    TITLE = "")
a.THE_HEADER.REQ_IF_HEADER=header

# More code for initializing fields

try:
    print(a.toxml());
except Exception as e:
    print(e.details())

Could you give me some pointers as to what I'm doing wrong and how I can still achieve the intended goal? I assume it's related to the super constructor somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions