Re: sqlalchemy is returning the wrong data

2007-08-08 Thread Tomasz Nazar
On 8/7/07, Mike Orr [EMAIL PROTECTED] wrote:


 On 8/6/07, jose [EMAIL PROTECTED] wrote:
  On a different note with my current setup (using extension=sac.ext) I
  thing that the explicit save (rec.save() from the example above) is
  not really necessary is it?

 No, sac.ext implicitly does the save for yoi.



.. and this becomes problem, when one doesn't want to do it. (at least
became for me)
I sometimes do not need each object created to be saved in DB
automagically..
I have deleted 'sac.ext' from my configuration and manage objects by hand
with `save(object)'





-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



sqlalchemy is returning the wrong data

2007-08-06 Thread jose

I have a perplexing problem and I'm really hopping that there is a
setting or something stupid that I've missed.  Here is the issue, I
have an application most of my page data is coming from a postgres
database.  I've designed an admin interface which allows you to edit
the database, however, when I leave the admin interface and look at
the page as a normal user, I see old data, not the new data.  If I
look at the database directly with pgadmin the new data has been
entered.  I am using postgres, python 2.4 pylons 0.9.6 rc2.  Here is
some example code:

ini file:
sqlalchemy.default.url = postgres://user:[EMAIL PROTECTED]/epathology


model:
from sqlalchemy import *
from sqlalchemy.orm import *
form sqlalchemy.ext.assignmapper import assign_mapper
from sacontext import PylonsSAContext

sac = PylonsSAContext()
sac.add_engine_from_config('default')
ctx = sac.session_context

table1 = Table('table1', sac.metadata, autoload=True)
class Table1(object):
pass
assign_mapper(ctx, Table1, table1, extension=sac.ext)


to set data I do:
rec = model.Table1.get(id)
rec.someattribute = new value
rec.save()  # I has not been doing this initially, I just added this
to see if it would help, it did not
model.sac.session.flush()

to get data I do:
data = model.rec.select()


This seems to work, however like I said when I edit the data more
often then not the application reflects old data, like its getting
data from a cache or using an old session to retrieve data from.  What
am I doing wrong? this is really frustrating.  Well thanks for any and
all help


Jose


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: sqlalchemy is returning the wrong data

2007-08-06 Thread askel

let me guess, you do not clear database session before/after each
request

On Aug 6, 12:02 pm, jose [EMAIL PROTECTED] wrote:
 I have a perplexing problem and I'm really hopping that there is a
 setting or something stupid that I've missed.  Here is the issue, I
 have an application most of my page data is coming from a postgres
 database.  I've designed an admin interface which allows you to edit
 the database, however, when I leave the admin interface and look at
 the page as a normal user, I see old data, not the new data.  If I
 look at the database directly with pgadmin the new data has been
 entered.  I am using postgres, python 2.4 pylons 0.9.6 rc2.  Here is
 some example code:

 ini file:
 sqlalchemy.default.url = postgres://user:[EMAIL PROTECTED]/epathology

 model:
 from sqlalchemy import *
 from sqlalchemy.orm import *
 form sqlalchemy.ext.assignmapper import assign_mapper
 from sacontext import PylonsSAContext

 sac = PylonsSAContext()
 sac.add_engine_from_config('default')
 ctx = sac.session_context

 table1 = Table('table1', sac.metadata, autoload=True)
 class Table1(object):
 pass
 assign_mapper(ctx, Table1, table1, extension=sac.ext)

 to set data I do:
 rec = model.Table1.get(id)
 rec.someattribute = new value
 rec.save()  # I has not been doing this initially, I just added this
 to see if it would help, it did not
 model.sac.session.flush()

 to get data I do:
 data = model.rec.select()

 This seems to work, however like I said when I edit the data more
 often then not the application reflects old data, like its getting
 data from a cache or using an old session to retrieve data from.  What
 am I doing wrong? this is really frustrating.  Well thanks for any and
 all help

 Jose


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: sqlalchemy is returning the wrong data

2007-08-06 Thread Mike Orr

On 8/6/07, jose [EMAIL PROTECTED] wrote:

 How do I clear the database session? I thought sacontext took care of
 that?

del sac.session_context.current

This is normally put in the base controller before the subclass call.

If you don't do this before the different users, it will hold
records in memory and assume they are the latest data.  Deleting the
session (which forces a new one to be created at next access) clears
out these memory records.  Of course, which stale data you have
depends on which request the current thread last handled, which is
unpredictable.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: sqlalchemy is returning the wrong data

2007-08-06 Thread Jose Galvez
Dear Mike,
I added the del sac.session_context.current to my base.py file and that
fixed the problem.  Thank you so much for the help I can't tell you how much
this was driving me nuts
Jose

On 8/6/07, jose [EMAIL PROTECTED] wrote:


 Thanks Mike,
 So just to clarify I need to del the current session with every
 request is that right?  Is there ever a situation where I would not
 want to del the current session with every request?

 On a different note with my current setup (using extension=sac.ext) I
 thing that the explicit save (rec.save() from the example above) is
 not really necessary is it?

 Thanks for the help

 Jose



 On Aug 6, 1:49 pm, Mike Orr [EMAIL PROTECTED] wrote:
  On 8/6/07, jose [EMAIL PROTECTED] wrote:
 
 
 
   How do I clear the database session? I thought sacontext took care of
   that?
 
  del sac.session_context.current
 
  This is normally put in the base controller before the subclass call.
 
  If you don't do this before the different users, it will hold
  records in memory and assume they are the latest data.  Deleting the
  session (which forces a new one to be created at next access) clears
  out these memory records.  Of course, which stale data you have
  depends on which request the current thread last handled, which is
  unpredictable.
 
  --
  Mike Orr [EMAIL PROTECTED]


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---