Fix work order, maintenance and schedule polymorphic serialization - #80
Merged
Merged
Conversation
…asserting, and send cleared ones as cleared
The work order, maintenance and maintenance schedule serializers read their
polymorphic type with snapshot.attr('<key>_type'), but those models declare no
such attribute, so saving one in a debug build failed with "Model has no
attribute named 'target_type' defined". They now read it through
snapshot.attributes().
Ember Data only calls serializePolymorphicType for a related record that is
present, so removing a target or assignee sent null embedded data while the
_uuid and _type columns kept the old record. Unset relationships are now sent
with both cleared.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v0.2.1 #80 +/- ##
================================================
Coverage 100.00% 100.00%
================================================
Files 115 116 +1
Lines 2922 2931 +9
Branches 697 698 +1
================================================
+ Hits 2922 2931 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Editing a work order in the console and choosing a target asset or assignee failed on save with:
The work order, maintenance and maintenance schedule serializers read the polymorphic type with
snapshot.attr('<key>_type'). Those models declare no such attribute, and Ember Data asserts on an undeclared one in debug builds.Clearing a target or assignee also never reached the server. Ember Data only calls
serializePolymorphicTypefor a related record that is present, so a removed relationship went out asnullembedded data while<key>_uuidand<key>_typestill pointed at the old record.Change
snapshot.attributes(), which returnsundefinedfor an undeclared attribute instead of asserting.clear-unset-polymorphic-relationshipsutil sends each unset polymorphic relationship with its_uuidand_typeset tonull.Tests
Needed by fleetbase/fleetops#325.