[sqlalchemy] Re: Strange caching problem with Apache

2008-03-31 Thread john spurling



On Mar 29, 8:11 am, Lukasz Szybalski [EMAIL PROTECTED] wrote:
 On Fri, Mar 28, 2008 at 10:54 PM, Graham Dumpleton



 [EMAIL PROTECTED] wrote:

   On Mar 29, 11:02 am, Michael Bayer [EMAIL PROTECTED] wrote:
On Mar 28, 2008, at 7:56 PM, john spurling wrote:

 I added debugging to get id(session) and len(list(session)). The
 session id is unique every time, and len(list(session)) is 0. I also
 called session.clear() before using it. Unfortunately, the caching
 behavior persists.

 Any other suggestions? Thank you very much for your time and help!

if its zero, then the Session isnt caching.  Something is going on
HTTP/process-wise.

   Could it be that because Apache is a multi process web server (on
   UNIX), that OP is getting confused through subsequent requests
   actually hitting a different process.

   That said, sqlalchemy as I understood it was meant to deal with that,
   ie., change made from one process should be reflected in another
   process straight away upon a new query, ie., cached data should be
   replaced. Is it possible that what ever insures that has been
   disabled.

   OP should perhaps print out os.getpid() so they know which process is
   handling the request each time. This may help to explain what is going
   on.

   Graham

 What are you using to handle http requests? turbogears? psp?

 Would converting from mod_python to mod_Wsgi help in this situation?

 Lucas

I'm using mod_python's publisher handler to handle requests. I'm not
familiar with mod_Wsgi, but I'll look into it.

The plot thickens: I rewrote the function to just get a connection
from the engine and send it raw SQL, and the caching behavior still
persists.

Thanks,
john

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Strange caching problem with Apache

2008-03-28 Thread john spurling

I'm having a strange caching problem when using SQLAlchemy with Apache
and mod_python. Using the ORM, I have a class that maps to a simple
table with two columns and no foreign keys. When I get an HTTP
request, I get the desired object by primary key and return the value
of the attribute that maps to the other column. This works fine when
Apache first loads, but if the value stored in the column of the
desired object changes (e.g. by simply running an UPDATE in the MySQL
command line), the new value will not be returned in the code. Here's
a synopsis of the code:


engine = sa.create_engine('mysql://[EMAIL PROTECTED]/project',
encoding='utf-8', echo=False)
metadata = MetaData()
metadata.bind = get_engine()
users_table = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('mojo', Integer, nullable=False,
default=0),
mysql_engine='InnoDB'
)
class User(object):
def __init__(self, id):
self.id = id
self.mojo = 0
def toResult(self):
return {'user_id': self.id,
'mojo': self.mojo,
'result_code': 0,
}
mapper(User, users_table)
Session = sessionmaker(bind=engine, autoflush=True,
transactional=True)
def log_debug(msg):
# custom logging function that logs to a file using the std lib
logging module
def get_user(user_id):
db = Session()
user = db.query(User).filter(User.id == user_id).first()
res = user.toResult()
log_debug(pelf_requests.balance, res)
db.close()
return res


The funny part is that if I run this very same code in a standalone
Python process (where the process is kept alive, like the Apache
process), there is no caching behavior; the correct value is returned
every single time. If it's run in Apache, I can see the incorrect
value get returned in the logs (in the 'get_user' function above). In
either case, I see the query getting logged in MySQL's query logs.

Any ideas at all? I've searched through both the mod_python and
sqlalchemy archives and haven't found anything appropriate.

The versions of all pertinent software are listed below:
SQLAlchemy: 0.4.2p3-1 (Ubuntu hardy package)
Apache: 2.2.4-3 (Ubuntu gutsy)
mod_python: 3.3.1-2 (Ubuntu gutsy)
Python: 2.5.1-5 (Ubuntu gutsy)

Thanks in advance for any insight or suggestions.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Strange caching problem with Apache

2008-03-28 Thread john spurling



On Mar 28, 4:12 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Mar 28, 2008, at 6:42 PM, john spurling wrote:



  The funny part is that if I run this very same code in a standalone
  Python process (where the process is kept alive, like the Apache
  process), there is no caching behavior; the correct value is returned
  every single time. If it's run in Apache, I can see the incorrect
  value get returned in the logs (in the 'get_user' function above). In
  either case, I see the query getting logged in MySQL's query logs.

  Any ideas at all? I've searched through both the mod_python and
  sqlalchemy archives and haven't found anything appropriate.

 that is the symptom of a Session being reused - that the SQL is issued
 but it returns the existing identity map version.  But the code you've
 illustrated should not have this problem since you are creating and
 closing a Session within the scope of a function call (but you said,
 that's only a synopsis of the code which I assume means it's not
 verbatim).   I'd add logging which includes the in-memory identity of
 the Session in use as well as assertions that it's empty before use
 (assert len(list(session)) == 0).  if a preceding session.clear()
 fixes the problem thats also a sign of that issue.

I added debugging to get id(session) and len(list(session)). The
session id is unique every time, and len(list(session)) is 0. I also
called session.clear() before using it. Unfortunately, the caching
behavior persists.

Any other suggestions? Thank you very much for your time and help!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---