Skip to content
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

Fix obj_c types to not overwrite jsonDict with nil #201

Merged
merged 2 commits into from
Nov 9, 2021

Conversation

geoffmacd
Copy link
Contributor

When the inner subType serializer returns nil as it does with return [jsonDict count] > 0 ? jsonDict : nil, this causes the outer/parent serializer to overwrite the mutable jsonDict to nil, resulting in a nil result when the .tag field was going to be added... In our case the DBCAMERAUPLOADSMOBILEMediaMetadataSerializer serializer returned nil when it needed a .tag field to be successful server-side

General Contributing

  • [x ] Have you read the Code of Conduct and signed the CLA?

Is This a Code Change?

  • Non-code related change (markdown/git settings etc)
  • [ x] Code Change
  • Example/Test Code Change

Validation

  • Have you ran tox?
  • Do the tests pass?

When the inner subType serializer returns nil as it does with `return [jsonDict count] > 0 ? jsonDict : nil`, this causes the outer/parent serializer to overwrite the mutable `jsonDict` to nil, resulting in a nil result when the `.tag` field was going to be added... In our case the  `DBCAMERAUPLOADSMOBILEMediaMetadataSerializer` serializer returned nil when it needed a `.tag` field to be successful server-side
@codecov
Copy link

codecov bot commented Nov 9, 2020

Codecov Report

Merging #201 (2a30f69) into main (68bc875) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #201   +/-   ##
=======================================
  Coverage   51.60%   51.60%           
=======================================
  Files          37       37           
  Lines        8400     8400           
  Branches     1790     1790           
=======================================
  Hits         4335     4335           
  Misses       3751     3751           
  Partials      314      314           
Flag Coverage Δ
unit 51.60% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
stone/backends/obj_c_types.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68bc875...2a30f69. Read the comment docs.

@geoffmacd geoffmacd requested review from xuyanke and rafe-g November 9, 2020 21:04
@greg-db greg-db requested a review from yuxiang-he November 9, 2020 21:13
@@ -1120,7 +1120,7 @@ def emit_serializer():
if is_user_defined_type(data_type):
if is_struct_type(data_type) and \
not data_type.has_enumerated_subtypes():
self.emit('jsonDict = [{} mutableCopy];'.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing i'd be worried about here is that in the old version, we are relying on the fact that we either get a brand new dictionary or nil. I the new code, we are adding the serialized dictionary to whatever jsonDict already contains. Are we 100% certain that every instance where this is used does not have an instance of jsonDict with some values already in it??

Something safer (if your unsure about my question above) would be to do something like:

jsonDict = [{} mutableCopy] ?: [[NSMutableDictionary alloc] init];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the deleted code, I think your saying that I should do

let additionDict = [{} mutableCopy] ?: [[NSMutableDictionary alloc] init]; // to guarantee non-nilness
[jsonDict addEntriesFromDictionary: additionDict]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are adding nil entries like [jsonDict addEntriesFromDictionary:nil], the json will still be non-nil. so we don't need a additionDict to be non-nil

@geoffmacd
Copy link
Contributor Author

@yuxiang-he could I have a review please?

@ianrahman ianrahman removed the request for review from xuyanke November 4, 2021 15:32
@rogebrd rogebrd merged commit b55317b into dropbox:main Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants