Skip to content

Conversation

@JGrothoff
Copy link
Contributor

Currently, the copy of a submodel with Date properties using pythons built-in copy.copy or copy.deepcopy fails with the following error:

File "basyx-python-sdk\basyx\aas\model\datatypes.py", line 49, in new
res: "Date" = datetime.date.new(cls, year, month, day) # type: ignore # pickle support is not in typeshed
TypeError: 'bytes' object cannot be interpreted as an integer

The error can be reproduced with (see test added in this PR):

import copy
from basyx.aas import model

date = model.datatypes.Date(2020, 1, 24)
date_copy_shallow = copy.copy(date) # will Fail
date_copy_deep = copy.deepcopy(date) # will Fail

I don't know where the error comes from, but when the class is copied the year argument gets a bytestring and month as well as dayare None.
However, overwriting __copy__ for shallow copies and __deepcopy__ seems to solve the issue.

@JGrothoff JGrothoff changed the title model.datatypes: fix error when copy Data types model.datatypes: fix error when copy Dates Sep 16, 2024
Copy link
Contributor

@s-heppner s-heppner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your contribution!

@s-heppner s-heppner merged commit 47f5e61 into eclipse-basyx:main Oct 2, 2024
@JGrothoff JGrothoff deleted the fix/copy_date branch November 18, 2024 10:34
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

Successfully merging this pull request may close these issues.

2 participants