2
votes

According to the documentation I have to pass in first the key, and then I shall pass in all the properties that I would like to initialise, so that the model is saved. All of that is done in form of a **kwargs.

The definition seems to be like this:

def _get_or_insert(*args, **kwds):

This is the way I intended to use it, but yet it throws an exception:

record1, is_created = Record.get_or_insert(record_key, {'record_date' : event1.date_time, 'user' : user.key})

The model is defined as:

class Record(ndb.Model):
    user = ndb.KeyProperty(kind=User)
    record_date = ndb.DateProperty(required=True)

Exception:

File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 3396, in _get_or_insert_async cls, name = args # These must always be positional. ValueError: too many values to unpack

Any advice?

1

1 Answers

4
votes

kwargs should be passed as key/value pairs. Try something like:

record1, is_created = Record.get_or_insert(record_key, record_date = event1.date_time,  user = user.key)