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

Store Structured Properties in backwards compatible way #184

Merged
merged 4 commits into from
Sep 4, 2019

Conversation

chrisrossi
Copy link
Contributor

The NDB rewrite, when storing values for structured properties, has been taking advantage of the native Datastore capability to arbitrarily nest entities as property values. Data written using the new NDB, however, would not be compatible with the legacy (Python 2) version, which always only stores a single entity in Datastore, using dotted property names to store the values of structured properties.

This patch introduces a new context flag, legacy_data, which, when True, causes NDB to store data in such a way as to be backwards compatible with the old version. The flag is True by default, requiring users to make a conscious decision to break backwards compatibility.

Fixes #178

@chrisrossi chrisrossi requested a review from cguardia September 3, 2019 18:58
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 3, 2019
Copy link
Contributor

@cguardia cguardia left a comment

Choose a reason for hiding this comment

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

Looks good.

@@ -3861,6 +3899,48 @@ def _get_value_size(self, entity):
values = [values]
return len(values)

def _to_datastore(self, entity, data, prefix="", repeated=False):
"""Override of :method:`StructuredProperty._to_datastore`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather, an override of Property._to_datastore, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep.

@chrisrossi chrisrossi merged commit 5439abd into googleapis:master Sep 4, 2019
@chrisrossi chrisrossi deleted the legacy-structured-props branch September 4, 2019 16:30
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
3 participants