17 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Use of new_instance(...| From | Sent On | Attachments |
|---|---|---|
| Phillip J. Eby | 27 Mar 2008 11:51 | |
| jason kirtland | 27 Mar 2008 12:01 | |
| Michael Bayer | 27 Mar 2008 12:10 | |
| Michael Bayer | 27 Mar 2008 12:42 | |
| Phillip J. Eby | 27 Mar 2008 14:06 | |
| jason kirtland | 27 Mar 2008 14:25 | |
| Phillip J. Eby | 27 Mar 2008 17:38 | |
| jason kirtland | 27 Mar 2008 18:08 | |
| Phillip J. Eby | 27 Mar 2008 21:54 | |
| Michael Bayer | 28 Mar 2008 06:44 | |
| Phillip J. Eby | 28 Mar 2008 07:57 | |
| Michael Bayer | 28 Mar 2008 08:37 | |
| jason kirtland | 28 Mar 2008 08:55 | |
| Phillip J. Eby | 28 Mar 2008 09:13 | |
| jason kirtland | 28 Mar 2008 09:26 | |
| Michael Bayer | 28 Mar 2008 09:28 | |
| Michael Bayer | 28 Mar 2008 09:53 |
| Subject: | [sqlalchemy] Re: Use of new_instance() in the user-defined-state branch?![]() |
|---|---|
| From: | Michael Bayer (mike...@zzzcomputing.com) |
| Date: | 03/28/2008 06:44:44 AM |
| List: | com.googlegroups.sqlalchemy |
On Mar 28, 2008, at 12:55 AM, Phillip J. Eby wrote:
Sadly, about the only way for me to implement that without code duplication will be to temporarily change the item's __class__ to a subclass with an empty __init__ method. Unless there's a way to change the generated __init__ method to take an extra flag or check a per-thread variable to skip the bits you don't want? What are the bits you don't want run, anyway? That is, what specifically mustn't happen?
an end-user's __init__ method is not run when the object is loaded from the DB since the ORM is going to populate its state explicitly. its for similar reasons that pickle.loads() doesn't call __init__. Its a common use case that someone's class needs to be constructed differently when it is newly created vs. when it is re-populated from the DB.
The usual method we have of modifying this behavior is to use a MapperExtension where you implement create_instance(). Then you can build the object any way you want, using __init__, whatever. Why is that not an option here ? ( or has it just not been mentioned ?)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to
sqla...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---




