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: check for legacy local structured property values #365

Merged

Conversation

cguardia
Copy link
Contributor

…when converting from base type

refs #359

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 12, 2020
@cguardia cguardia requested a review from chrisrossi March 12, 2020 18:04
Copy link
Contributor

@chrisrossi chrisrossi left a comment

Choose a reason for hiding this comment

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

Looks fine. Suggested some minor cleanup in code that happened to be nearby.

# See https://github.com/googleapis/python-ndb/issues/359
if self._compressed and isinstance(value, ds_entity_module.Entity):
return

if self._compressed and not isinstance(value, _CompressedValue):
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this isn't part of the PR, but it's drawn my eye to this code, and I have a couple of questions.

# See https://github.com/googleapis/python-ndb/issues/359
if self._compressed and isinstance(value, ds_entity_module.Entity):
return

if self._compressed and not isinstance(value, _CompressedValue):
if not value.startswith(_ZLIB_COMPRESSION_MARKER):
value = zlib.compress(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why compress here if we're just going to decompress below? Can we just return?

Copy link
Contributor

Choose a reason for hiding this comment

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

And just below here, in that last if statement, don't we already know it's a _CompressedValue at that point? Do we need the if?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that compressing and then immediately decompressing is foolish. Will change that. I do think the last check is needed, because it could happen that we could be dealing with a non-compressed property.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, now that I look at it, I think that check is actually the only needed code in that method. Thanks for bringing it to my attention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I had to follow the different possibilities step by step to get a better grasp. The only possible improvement was your first suggestion to avoid compressing and return instead. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants