--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Nick, any comment on my approach of changing the PolyModel's class via db.to_dict and creating a new model with the same key? That seems to me like a relatively clean & safe way to do it. The desire to be able to do this for my case, is to be able to move records from Person to User, then User to SuperUser, gaining extra fields needed as the person descends the hierarchy. I suspect that's a fairly common scenario, and seems almost exactly the type of thing that PolyModel was designed for.
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/O3DQBp7xtBAJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Nick,Hi. As a rule, when someone uses the term "code smell", that's a
> It's never 'safe' to mess with the internals of Python like this. As a rule,
> if you're trying to change the class of an existing object, that's a code
> smell, and you should almost certainly be implementing it differently, such
"cliche smell".
Google bundles django with AppEngine, and django messes with the
internals of Python like crazy, so Google hopefully does think it's
safe in some cases.
I want to put some data into the datastore. Depending on the value of
that data, I want it to map to a different class when I get it back.
Changing the __class__ attribute currently works. I posted this
question for two reasons:
- to find out whether or not this approach was likely to break in
some cases or with future versions of DataStore API.
- because changing __class__ feels hackish and I was hoping someone
might suggest a better approach
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Nick,
Thanks for your reply. I'm sure you're bored of this thread so I'll
> It _is_ a hack. A better approach would be to use a single class with
> appropriate properties, or create a new instance of a new class and discard
> the old one at such time as you need to make the change.
try to summarise.
To take another example, SQLAlchemy supports what it calls "Single
Table Inheritance" - http://www.sqlalchemy.org/docs/orm/inheritance.html#single-table-inheritance
. In this approach, there is a field "type" that SQLAlchemy uses to
determine what class the row should be mapped to. So if you change the
'type' you change the class.
You seem to be saying that each record in the datastore should map to
one and only one Python class, so a similar approach doesn't work.
Polymodel Objects in the GAE Datastore have a property "class" which
stores a list of super classes. This property appears to be used by
the DataStore API in a similar way to how "type" is used by
SQLAlchemy. It's currently possible to change the value of this field
by setting the __class__ attribute of an instance and saving it back
to the DataStore. However, you state:
Somewhat cryptic, but I'll take your word for it.
"You're breaking any number of invariants by doing this, so things may
break without notice at any time. "
So perhaps the question boils down to whether or not there _is_ a
reliable way to change the value of the class property for polymodel
records? I'm guessing the answer is "no", but I'd like to check.
Thanks
Patrick
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Tim,
> I actually think a Expando model might be more appropriate combined with
> adapters.
Hi. As far as I understand it, Expando models allow you to store
additional data, but I'm looking to change behaviour, not state.