On Jun 28, 2011, at 4:29 AM, NiL wrote:
> Hi list,
>
> I have a turbogears controller, the model are elixir defined.
>
> def copy(self, scenario_id, **kwargs):
> """ copy a scenario
>
> :param scenario_id: id of a :class:`model.Scenario`
> :type media_id: string
> """
> user = request.environ['repoze.who.identity']['user']
> scenario = Scenario.get(scenario_id)
>
> clone = Scenario(owner = user)
> Session.add(clone)
> Session.commit()
>
> from nose.tools import set_trace; set_trace()
> details = kwargs.get('details', False)
> return dict(scenario=clone, details=details)
commit() expires all attributes. As soon as they are accessed again, the
database must be queried, and a new transaction begins.
the real issue here is that its better to have a single commit() that encloses
a series of operations, and nothing happens outside of the commit(). Calling
commit() in an ad-hoc fashion inside of business methods is not a good pattern
and suggests the application doesnt have clear boundaries as to when
transactions begin and end.
>
> I'm bound to a postgres database.
>
> just before the commit, I can observe a "<IDLE> in transaction" lock
> in PG (normal)
> Then I commit() the output from sqla debug is something like :
>
> 2011-06-28 09:56:16,804 INFO sqlalchemy.engine.base.Engine.0x...3dcc
> BEGIN (implicit)
> 2011-06-28 09:56:16,806 INFO sqlalchemy.engine.base.Engine.0x...3dcc
> SELECT "user".user_id AS user_user_id, "user".user_name AS
> user_user_name, "user".password AS user_password,
> "user".password_check AS user_password_check, "user".email_address AS
> user_email_address, "user".display_name AS user_display_name,
> "user".created AS user_created, "user".active AS user_active,
> "user".permission_assoc_id AS user_permission_assoc_id
> FROM "user"
> WHERE "user".user_id = %(param_1)s
>
> and thus <IDLE> in transaction is back.
> When I run this in test, the next thing is the tear down, that will
> try to drop all tables to run next test, and everything will get
> stuck....
>
>
> what am I missing here ?
>
> regards
> NIL
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.