[FIX] migrate_context: widgets crash when migrating context without version#3603
[FIX] migrate_context: widgets crash when migrating context without version#3603janezd merged 1 commit intobiolab:masterfrom
Conversation
e1ff0e5 to
908594c
Compare
Codecov Report
@@ Coverage Diff @@
## master #3603 +/- ##
==========================================
- Coverage 84.07% 84.07% -0.01%
==========================================
Files 370 370
Lines 67252 67253 +1
==========================================
- Hits 56541 56540 -1
- Misses 10711 10713 +2 |
|
I may be wrong, but this doesn't looks like a fix but just a workaround. As I understand, the problem is that version that is passed to the migration is wrong -- for instance, settings are version 3, while the argument says that they're 0. If migration cannot rely on being passed the correct version, it's the same as if settings didn't have versions and migration would have to guess. |
bf39bd3 to
0808373
Compare
|
This problem is caused by contexts being mutable. After widget settings are packed into node.properties, update_defaults is called. This one calls settings_from_widget, which replaces context's values with a new dict that does not contain the Updating pack to copy contexts should solve the issue. A similar fix already exists in write_default_to_file |
0808373 to
961d202
Compare
|
@astaric, kudos. I needed ten minutes of jumping around the code just to understand your comment -- and it's not because of the complexity of the comment but of the code. (Which is again not your fault; it used to be much worse and let's not talk about this. :)) Your patch copies contexts to prevent overwriting them with ill-formed, version-less contexts later on. But why are contexts without versions even allowed? Why is |
|
Historical reasons. Version support was first added to pack_data methods and later to write_defaults_file. Each time, the same change was made to methods in SettingsHandler and ContextHandler. I agree that adding the version to context in settings_from_widget is a better place that covers both paths. Returning a value from pack_data that can/will be changed in the future seemed wrong, this is why I suggested returning copies of contexts. |
|
It would still be nice, though, if settings always had a version, but let's do it in another PR. |
Issue
Most widgets that implement migrate_context crash upon undo.
To reproduce see #3600.
Description of changes
Add checks for required context values to all widget that implement migrate_context.
Includes