Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Repeated nested properties of StructuredProperty #40

Closed
brianmhunt opened this issue Jan 14, 2016 · 5 comments
Closed

Repeated nested properties of StructuredProperty #40

brianmhunt opened this issue Jan 14, 2016 · 5 comments
Assignees

Comments

@brianmhunt
Copy link

I'm just copying the gist of a SO question. In particular, the docs for AppEngine state:

Although a StructuredProperty can be repeated and a StructuredProperty can contain another StructuredProperty, beware: if one structured property contains another, only one of them can be repeated.

This implies that nested structured properties cannot both be repeated. However, the condition in the code appears to be that any repeated property cannot be contained in a repeated StructuredProperty, as doing so will throw something like:

TypeError: This StructuredProperty cannot use repeated=True because its model class (KeyList) contains repeated properties (directly or indirectly).

It may be that the documentation I've quoted at the top are just unclear or I've misread them.

However, if a repeated StructuredProperty ought to be able to contain repeated properties (that are not of the StructuredProperty variety), then the solution might be to change the condition from if modelclass._has_repeated to (something like):

    if modelclass._has_repeated and isinstance(modelclass, StructuredProperty):

Cheers

@brianmhunt
Copy link
Author

While it does not appear determinative, I also just noted the documentation in the code:

Structured property types can be nested arbitrarily deep, but in a
hierarchy of nested structured property types, only one level can have
the repeated flag set. It is fine to have multiple structured
properties referencing the same model class.

It's not clear if the restriction is intended to be one level of structured property, or the leaf properties can also be repeated.

@theacodes
Copy link

@bryanmau1 can you take a look at this? If it's a documentation issue, feel free to file a bug against the docs.

@pcostell
Copy link

@jonparrot -- Yup this is a docs issue. Only one layer of repeated properties is allowed in ndb. So a StructuredProperty can be repeated but then none of the properties in that StructuredProperty can be repeated.

@bryanmau1
Copy link
Contributor

Thanks for the reply, we'll fix the docs.

For future reference, the proper place to bring up issues about NDB is this GitHub.

https://github.com/GoogleCloudPlatform/datastore-ndb-python

@brianmhunt
Copy link
Author

Thanks @bryanmau1 & @pcostell

Incidentally, the Golang docs are different and my need some attention too. Cheers

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants