David Haddad
David Haddad

Reputation: 3936

Why db.Key.from_path raise an error when id_or_name and kind are passed as keyword arguments, but not as positional arguments?

>> db.Key.from_path(kind='Entity', id_or_name='name')
# Error 'Excess keyword arguments ' + repr(kwds))

>> db.Key.from_path('Entity', 'name')
# Works okay

Was the google.appengine.ext.db.Key.from_path() designed like that for a specific reason?

Upvotes: 0

Views: 222

Answers (1)

joaquin
joaquin

Reputation: 85603

Because positional arguments can not be passed as keyword (default) argumentss.
This is not a problem of gae but the way python function arguments work.

From appeng docs:

Key.from_path(kind, id_or_name, parent=none, namespace=None, **kwds)

where:

**kwds
Keyword arguments. The method supports one keyword argument, parent,
which specifies a parent entity to prepend to the given path.
Its value is the parent's Key.

So "kind", "id_or_name" are not keywords but names to indicate positional arguments.

Upvotes: 2

Related Questions