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

xsdata seems to have an issue with metadata = {"type": "ignore"} #1091

Open
skinkie opened this issue Nov 8, 2024 · 4 comments
Open

xsdata seems to have an issue with metadata = {"type": "ignore"} #1091

skinkie opened this issue Nov 8, 2024 · 4 comments

Comments

@skinkie
Copy link
Contributor

skinkie commented Nov 8, 2024

testcase.zip

Running the code below result into.

This works
WheelchairAccess(value=<LimitationStatusEnumeration.FALSE: 'false'>)
This fails
Told you so...
Traceback (most recent call last):
  File "/tmp/xsdata_bug.py", line 22, in <module>
    print(site_frame.stop_places.stop_place[0].accessibility_assessment.limitations.accessibility_limitation)
  File "/usr/lib/python3.12/dataclasses.py", line 262, in wrapper
    result = user_function(self)
             ^^^^^^^^^^^^^^^^^^^
  File "<string>", line 3, in __repr__
AttributeError: 'AccessibilityLimitation' object has no attribute 'validity_conditions_or_valid_between'

Removing the attributes with type=ignore, the code functions as expected.

@dataclass(kw_only=True)
class AccessibilityLimitation(AccessibilityLimitationVersionedChildStructure):
    class Meta:
        namespace = "http://www.netex.org.uk/netex"

    validity_conditions_or_valid_between: Any = field(
        init=False,
        metadata={
            "type": "Ignore",
        },
    )
    alternative_texts: Any = field(
        init=False,
        metadata={
            "type": "Ignore",
        },
    )
from pathlib import Path

from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.parsers.config import ParserConfig
from xsdata.formats.dataclass.parsers.handlers import LxmlEventHandler

from netex import PublicationDelivery, CompositeFrame, SiteFrame

context = XmlContext()
config = ParserConfig(fail_on_unknown_properties=False)
parser = XmlParser(context=context, config=config, handler=LxmlEventHandler)
pd = parser.parse(Path("/tmp/smaller.xml"), PublicationDelivery)
composite_frame: CompositeFrame = pd.data_objects.choice[0]
site_frame: SiteFrame = composite_frame.frames.common_frame[1]

print("This works")
print(site_frame.stop_places.stop_place[0].accessibility_assessment.limitations.accessibility_limitation.wheelchair_access)

print("This fails")
try:
    print(site_frame.stop_places.stop_place[0].accessibility_assessment.limitations.accessibility_limitation)
except:
    print("Told you so...")
    raise

print("Therefore this fails too")
try:
    print(site_frame.stop_places.stop_place[0])
except:
    print("Told you so...")
    raise
@tefra
Copy link
Owner

tefra commented Nov 9, 2024

Pleased provide a simple example for me @skinkie

@skinkie
Copy link
Contributor Author

skinkie commented Nov 9, 2024

@tefra the zip file attached contains everything, except for the generated NeTEx.

This is everything, just run xsdata_bug.py.
everything.zip

@skinkie
Copy link
Contributor Author

skinkie commented Nov 9, 2024

Pleased provide a simple example for me @skinkie

I read your other comment, I'll see how I can simplify. I wish there was some easy XML Schema GUI tooling for Linux as well.

@skinkie
Copy link
Contributor Author

skinkie commented Nov 9, 2024

@tefra small enough?

small-example.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants