Skip to content

Support EndpointsModel with properties repeated=True #86

Closed
catogonzalez opened this Issue Jan 9, 2014 · 3 comments

3 participants

@catogonzalez

Had the problem described and solved here:

http://stackoverflow.com/questions/20954164/how-to-retrieve-ndb-keyproperty-when-repeated-true-using-endpoints-proto-datasto/21009683#21009683

Suggest to change model.py line 227 and next as follows:

  # Only filter for non-null values...
  if current_value is not None:
      # ...and not empty arrays in case of properties with repeated=True
      if current_value:
          self._AddFilter(prop == current_value)

Didn't see how to create a pull request: sorry if this is not the correct way to contribute this suggestion and thanks for the great library!

@kdeus
kdeus commented Jan 10, 2014

A couple questions on this:

First, the latest version of model.py has a check just above the if current_value is not None (lines 231-234):

      if prop._repeated:
        if current_value != []:
          raise ValueError('No queries on repeated values are allowed.')
        continue

Wouldn't this already catch the repeated field and prevent the problem you're talking about? Are you using an older version of the library?

And also, could something like this be used change to your Contacts class/model to change the empty list to be None instead (I haven't tested this)?

        def emails(self):
                return ndb.get_multi(self.email_keys) or None
@dhermes
Google Cloud Platform member
dhermes commented Jan 18, 2014

I actually fixed this for a talk but it never made it in:
dhermes@8fb98c1

Also had another fix in that fork:
dhermes@3294d7e

@catogonzalez

Sorry for getting back so late.

@kdeus is right: I had an older version of the library and the latest version fixes the issue. Also, I haven't tried your proposed solution in my Contacts model but it might work well too.

Thanks to both @kdeus and @dhermes for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.