Skip to content

[Bug]: pyESDL #83

@ladderup

Description

@ladderup

Is there an existing issue for this?

  • I have searched the existing issues.

What happened?

I've been playing around with the pyESDL library.

I added the pyESDL library to QGIS 3.40.8 LTR (using Python 3.12) to build and export ESDL files. Initially everything worked perfectly, but at some point, calling esh.save() started to consistently crash QGIS with a fatal access violation:
Python code:
Eaxmple python script:
# New ESDL-object
es = EnergySystem(id=generate_uuid(), name="QGIS export") #generate EnergySystem
esi = esdl.EnergySystemInformation(id=generate_uuid()) #generate EnergySystemInformation
carriers = esdl.Carriers(id=generate_uuid()) #generate Carriers
HeatCommodity_supply_id = generate_uuid()
#HeatCommodity_supply_ret_id = HeatCommodity_supply_id + "_ret" #identical to supply_id + "_ret"
supply = esdl.HeatCommodity(id=HeatCommodity_supply_id,name="Supply",supplyTemperature=110.0) #generate HeatCommodity
#supply_ret = esdl.HeatCommodity(id=HeatCommodity_supply_ret_id,name="Supply_ret",returnTemperature=55.0)
carriers.carrier.extend([supply]) #attach carrier to carriers
#carriers.carrier.extend([supply_ret]) #not used: create during 'duplication'
esi.carriers = carriers #attach carriers to energySystemInformation
es.energySystemInformation = esi # attach EnergySystemInformation to EnergySystem

    inst = Instance(id=generate_uuid(), name="Generated instance") #generate Instance
    area = Area(id=generate_uuid(), name="Generated area") #generate Area
    inst.area = area  # attach area to intance
    es.instance.append(inst)  # attach instance to energySystem

    esh = EnergySystemHandler()
    esh.energy_system = es
    esh.save(params.export_path)

QGIS error:
Windows fatal exception: access violation

Current thread 0x0000531c (most recent call first):
File ".../esdl/resources/xmi.py", line 416 in _go_across
node = Element(tag)

Steps to reproduce the problem

After extensive testing, I tracked the root cause down to the installed version of lxml.

System details:

  • QGIS version: 3.40.8 LTR (OSGeo4W)
  • Python: 3.12
  • lxml version: 5.3.0 (default from pip)
  • pyESDL: unknown version (no __version__ string; likely recent)

Diagnosis:
The error disappears entirely when I downgrade lxml to version 4.9.3:

pip uninstall lxml
pip install lxml==4.9.3


This suggests that pyESDL is currently incompatible with lxml >= 5.0, possibly due to stricter tag handling or internal API changes introduced in lxml 5.x.

### What should have happened?

Request:
Could you confirm whether pyESDL officially supports lxml 5.x? If not, it might be useful to:

Pin the maximum version of lxml in requirements.txt (e.g. <5.0)

Add a warning in the README

Consider updating the XML serialization code for lxml 5.x compatibility in future versions

Let me know if you'd like a minimal reproducible example — I can provide a small script that triggers the crash reliably.

Thanks for the great library!

### What browsers do you use to access the UI?

None

### Additional information

_No response_

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions