Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Document NDB's introspection APIs #187

Open
GoogleCodeExporter opened this issue Jun 10, 2015 · 6 comments
Open

Document NDB's introspection APIs #187

GoogleCodeExporter opened this issue Jun 10, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

NDB does not officially support retrospection of created models. This is 
standard a feature that probably should be available in all APIs.

The current work-around is to use internal and undocumented attributes like 
("_properties" and _repeated) but this should be made part of the official API.

Original issue reported on code.google.com by arn...@gmail.com on 22 May 2012 at 10:22

@GoogleCodeExporter
Copy link
Author

[deleted comment]

1 similar comment
@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

[repost due to confusing typo]

Thanks for the reminder. The names starting with _ corresponding to property 
options are actually intended to be a part of the API. I'll make sure this is 
documented somewhere.

The reason these start with _ is that for StructuredProperty, property names of 
the model class would otherwise clash with the introspection API, e.g.

class A(Model):
  repeated = BooleanProperty()
class B(Model):
   a = StructuredProperty(A)

Now B.a.repeated refers to A's repeated property, while B.a._repeated is the 
value of B.a's repeated option.

Apologies for not having this clear in the docs.

Some more examples:

class Employee(Model):
 name = StringProperty()
 address = StringProperty(repeated=True)

>>> print Employee.name._repeated
False
>>> print Emplotee.address._repeated
True
>>>

The full collection of properties of a model is given as a class variable 
_properties; in the above example,

>>> print Employee._properties
{'name': StringProperty(), 'address': StringProperty(repeated=True)}
>>>

On Expando entities, the list of properties is an instance variable; e.g.

class X(Expando): pass

>>> x = X(foo=42, bar='hello')
>>> print x._properties
{'foo': GenericProperty(), 'bar': GenericProperty()}
>>>

Original comment by guido@google.com on 22 May 2012 at 4:28

@GoogleCodeExporter
Copy link
Author

Original comment by guido@google.com on 29 May 2012 at 6:22

  • Added labels: log-6477792

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

(Fixing the summary and metadata to reflect that this is just a documentation 
task.)

Original comment by guido@google.com on 2 Jul 2012 at 2:11

  • Changed title: Document NDB's introspection APIs
  • Added labels: Type-Task
  • Removed labels: Type-Defect

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

No branches or pull requests

2 participants