-
Notifications
You must be signed in to change notification settings - Fork 15
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
Serialiser_Engine: Update NullOrEmptyCheck to just check for Null #3364
Serialiser_Engine: Update NullOrEmptyCheck to just check for Null #3364
Conversation
@BHoMBot check compliance |
@peterjamesnugent to confirm, the following actions are now queued:
|
@BHoMBot check unit-tests |
@peterjamesnugent to confirm, the following actions are now queued:
There are 7 requests in the queue ahead of you. |
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 think the changes here most likely makes sense.
Caveat would be if we could end up with a similar issue again as the one you have just fixed, where we had some data that have name set to empty string as default for the class, then for whatever reason the name as been set to null, then the object serialised. When de-serialised than, the name will be skipped, and you will end up with a miss-match compared to the original object, where the de-serialised object will have the name set to the default value (most likely an empty string) but the original object having its name set to null.
A bit on the fence on this one, and the best way to handle it tbh. Could complicate the check by only including if it is not null or empty AND not equal to the default value for the class. This ofc makes the check more complex, but only way I can think of that guards against the problem above. Then you still have the edge case of someone changing the default value of the class, but that is a case I think we could live with.
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.
Actually, I second to the comment of @IsakNaslundBh - dealing with name may lead to issues in case the default value is overridden (see script here, all overrides can be quickly looked up as here). Also in the proposed shape, values equal to null
get deserialised to empty, so FromJson != ToJson
(see code comment with a fix and test in script above - however, it still does not address the general problem of overridden defaults).
So to summarise, personally I would rather always serialise the name as an optimal tradeoff between risk/effort and volume/performance (storing an empty name is literally a few characters in total).
Co-authored-by: Pawel Baran <pawel.baran@burohappold.com>
Added the check suggested by @pawelbaran as that solves the majority of cases serialising/deserialising. This does leave a mismatch for overriden properties though as commented above. Perhaps we should add an additional check for unit-tests that looks for null names or any string properties that is null so they can be updated rather than have to patch over the |
Are you against removing |
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.
Happy to approve the code changes, I think what we have now is an optimal trade-off. I see 2 alternatives here:
- allowing for bugs/inconsistencies we are aware of (in case of overridden default) - we ruled it out, not great
- checking whether
value.Name
is a default value of the property - I did quick research and it looks like this would require instantiating a dummy object, which is a massive overhead plus potential risk (think ofIImmutable
)
...so I think what we have now is best value that we can get for now, better alternatives to be rather searched in a separate thread 👍
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 would follow Ockham on this one. If removing code solves the problem, this is probably a good direction to consider.
More seriously, the exclusion of some properties from json was purely a minor but straightforward optimisation. If it stops being straightforward, then the best approach is indeed to remove it.
Some quick test confirms that this change
- doesn't have a significant impact on the size of the json (
BHoM_Guid
,_t
, and_bhomVersion
alone are already much longer) - does maintain the name value even when it is null
Although more testing is always good, I don't see any reason to have anymore than this simple one as long as the bot checks are passing so happy to approve.
@BHoMBot check required |
@pawelbaran to confirm, the following actions are now queued:
|
@pawelbaran to confirm, the following actions are now queued:
There are 17 requests in the queue ahead of you. |
@peterjamesnugent do you have any clue if the unit tests failure is caused by this PR? |
FAO: @FraserGreenroyd The check they wish to have dispensation on is unit-tests. If you are providing dispensation on this occasion, please reply with:
|
@BHoMBot this is a DevOps instruction. I am authorising dispensation to be granted on check ref. 26892311972 |
@pawelbaran I have now provided a passing check on reference |
@pawelbaran sorry, I didn't understand. |
@BHoMBot check ready-to-merge |
@pawelbaran to confirm, the following actions are now queued:
|
Issues addressed by this PR
Closes #3357
Test files
Unit tests
Overriden objects and non-overriden objects
Changelog
NullOrEmptyCheck
inSerialise
method forIBHoMObject
s to just checknull
forName
properties;CellularSectionFromBase
following changes to theSerialse
method;Additional comments