Hello Michael,
Thanks for quick answer!
Michael Bayer wrote:
> Marcin Krol wrote:
>
> rsv = session.query(Reservation).filter(Reservation.id ==
>> int(rid)).first()
>>
>> rhost =
>> session.query(Host).filter(Host.id.in_(rhostsel)).order_by(Host.ip).first()
>>
>> host =
>> session.query(Host).filter(Host.id.in_(hostsel)).order_by(Host.ip).first()
> these three queries may not return the same result each time, since you
> are calling first(). Subsequent results will be discarded, and if
> Host.ip contains repeats, you'll get non-deterministic results.
This does not really matter, since the above queries are only done in
Reservation update code and hostsel / rhostsel selection is reliable (I
get it from elsewhere), so I'm sure that update is correct (I have
phpPGAdmin opened and check db on each query and the values I read from
there are OK, i.e. update query sets them correctly and between the
updates in the web app every SELECT on those tables returns correct values).
>> This lasts until the restart of the webserver, upon which the correct
>> value is read into session again.
> is there any caching in use ? global variables ?
Yes. 'session' is a global variable created in another module like this:
Session=sessionmaker(bind=eng)
session=Session()
This variable is imported in the app from that another module that sets
up SQLA.
> the Session itself
> should be closed out after each request (i.e. session.close())
Really? Nowhere in the docs I have read I should do that, really...
Do you mean that I should do session.close() after each update? Or even
after each session.query()?
> so its not
> involved in the equation - data should not be carried over between
> requests
This is exactly what happens - it's as if session returned reference to
one of the previous attributes, randomly.
> unless you've specifically decided its safe to cache elsewhere.
I'm not doing any caching elsewhere.
> Sessions dont necessarily lose all their data "automatically" since strong
> references may remain between mutually-referencing objects (like in
> backrefs).
>> I have checked that on updating the object the correct value gets
>> written to the backend db. It's just subsequent queries to the current
>> session randomly return one of the former object attribute values.
> very easy to turn on SQL echoing, particularly DEBUG, and see exactly what
> queries are issued and what results they are returning.
I have indeed turned that on and looked there for hints, but I haven't
found anything - e.g. I can see queries and parameters, but not values
returned by SQL:
INFO:sqlalchemy.engine.base.Engine.0x...a98c:SELECT newhosts.id AS
newhosts_id, newhosts.ip AS newho
sts_ip, newhosts.hostname AS newhosts_hostname, newhosts.location AS
newhosts_location, newhosts.arc
hitecture_id AS newhosts_architecture_id, newhosts.os_kind_id AS
newhosts_os_kind_id, newhosts.os_ve
rsion_id AS newhosts_os_version_id, newhosts.virtualization_id AS
newhosts_virtualization_id, newhos
ts.shareable AS newhosts_shareable, newhosts.shareable_between_projects
AS newhosts_shareable_betwee
n_projects, newhosts.cpu AS newhosts_cpu, newhosts.ram AS newhosts_ram,
newhosts.notes AS newhosts_n
otes, newhosts.physical_box AS newhosts_physical_box,
newhosts.project_id AS newhosts_project_id
FROM newhosts, reservation_newhosts
WHERE %(param_1)s = reservation_newhosts.reservation_id AND newhosts.id
= reservation_newhosts.host_
id
INFO:sqlalchemy.engine.base.Engine.0x...a98c:{'param_1': 2}
No values returned in sight.
I have sql logging configured like this:
logging.basicConfig(filename=globalpath + os.sep + 'sql.log')
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
Thanks for help, Mike!
Regards,
mk
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---