-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
dbc: dump_string: set GenSigStartValue from Signal.raw_initial #569
dbc: dump_string: set GenSigStartValue from Signal.raw_initial #569
Conversation
Pull Request Test Coverage Report for Build 5064782045
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @juleq , @zariiii9003 ?
# synchronize the attribute for the signal start value with | ||
# the start value specified by the message object | ||
if signal.raw_initial is None and 'GenSigStartValue' in sig_attributes: | ||
del sig_attributes['GenSigStartValue'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are modifying signal.dbc.attributes
here, because you reassigned sig_attributes
on line 802. You should call sig_attributes.update(signal.dbc.attributes)
or create a deep copy of signal.dbc.attributes
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered about that, but if that's a bug, it also exists the way message.dbc.attributes['GenMsgCycleTime']
is handled in the current code right above my additions:
for message in database.messages:
# retrieve the ordered dictionary of message attributes
msg_attributes = OrderedDict()
if message.dbc is not None and message.dbc.attributes is not None:
msg_attributes = message.dbc.attributes
# synchronize the attribute for the message cycle time with
# the cycle time specified by the message object
if message.cycle_time is None and 'GenMsgCycleTime' in msg_attributes:
del msg_attributes['GenMsgCycleTime']
That was originally added in fcb2bcb. @andlaus can you comment on what your thinking was there? It looks to me like you were taking the opportunity at DBC write time to synchronize the Message DbcSpecifics with any changes made to the Message.cycle_time value. Since what I'm doing is an analogous operation on Signals, I used the same pattern.
If you still think that's wrong, though, @zariiii9003, I can fix it. Would you want it fixed for message.dbc.attributes['GenMsgCycleTime']
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was originally added in fcb2bcb. @andlaus can you comment on what your thinking was there? It looks to me like you were taking the opportunity at DBC write time to synchronize the Message DbcSpecifics with any changes made to the Message.cycle_time value.
I don't remember exactly, but I think that was the reason why. I'm pretty sure this can be implemented more elegantly, though.
Since what I'm doing is an analogous operation on Signals, I used the same pattern.
fine with me ;). if I understood @zariiii9003 correctly, he just wants to have this done in a more pythonic fashion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are modifying signal.dbc.attributes here, because you reassigned sig_attributes on line 802. You should call sig_attributes.update(signal.dbc.attributes) or create a deep copy of signal.dbc.attributes.
NB that the whole database is already deepcopied before it is written: https://github.com/cantools/cantools/blob/master/cantools/database/can/formats/dbc.py#L1862
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, dumping the database should have no side effects. The database should remain unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, dumping the database should have no side effects. The database should remain unchanged.
agreed. that's why the database object is deepcopied before doing the modifications. (It's a bit hacky but it has been like this since at least 2020 (cf 89b974cb3b0921a057bff352afe84fa844e23a8d)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the deepcopy already happens at the top (I'd missed that -- thanks @andlaus) I think your request is already met by this PR in its current form, do you agree @zariiii9003? Does it need anything else before you'd want to merge it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, dumping the database should have no side effects. The database should remain unchanged.
agreed. that's why the database object is deepcopied before doing the modifications. (It's a bit hacky but it has been like this since at least 2020 (cf 89b974cb3b0921a057bff352afe84fa844e23a8d)
I see. That module needs some refactoring 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. it is far from the only one, though ;)
I modeled this after the way GenMsgCycleTime is synchronized with Message.cycle_time.