asammdf icon indicating copy to clipboard operation
asammdf copied to clipboard

MDF.start_time property setter doesn't work properly

Open BenWhetton opened this issue 3 years ago • 1 comments

Python version

3.9.9 but I don't think this is a version dependent bug

Code

from asammdf.mdf import MDF
from datetime import datetime

mdf = MDF()
# This doens't call the property setter, instead it calls __setattr__
mdf.start_time = datetime.now()
# So the data is not set correctly
print(mdf._mdf.header.start_time) # shows the wrong value
# Instead, it sets this one
print(mdf._mdf.start_time) # shows the right value
# This calls the property getter, and doesn't return the set value
print(mdf.start_time) # shows the wrong value

Description

The MDF class has a start_time property and setter. However, the setter is never called if the user tries to set a value to start_time, __setattr__ is called instead. I can't find official docs but this stackoverflow post explains how attribute lookup works: https://stackoverflow.com/a/15751159. I can see two possible solutions:

  • Explicitly handle the start_time case in __setattr__
  • Move the start_time property to the mdf implementation classes (MDF4 etc.).

BenWhetton avatar May 05 '22 08:05 BenWhetton

@BenWhetton can you check the latest dev branch?

danielhrisca avatar Aug 09 '22 06:08 danielhrisca