I am using sqlalchemy version 0.5.5
and elixir version 0.7.1
I am having a problem where I have an application that uses elixir on
top of a database that can be updated by another application. If i
don't do a full restart of the first application it does not seem to
pickup the database changes.
I have tried all of the following:
session.remove()
session.expunge_all()
session.close_all()
session.expire_all()
session.clear()
session.flush()
session.close()
I have also tried to reload the module that is being called...
Any help would be greatly appreciated,
Thanks, David
> I am having a problem where I have an application that uses elixir on
> top of a database that can be updated by another application. If i
> don't do a full restart of the first application it does not seem to
> pickup the database changes.
>
> I have tried all of the following:
> session.remove()
> session.expunge_all()
> session.close_all()
> session.expire_all()
> session.clear()
> session.flush()
> session.close()
>
> I have also tried to reload the module that is being called...
Do you know that the in-memory objects (within the session or not) are
never automatically updated with the changes in the database? You have
to do session.query or session.merge.
Other than that, does the other application commit its changes?
Hope it helps,
--
Gaëtan de Menten
http://openhex.org
Thanks, David
On Dec 20, 5:39 am, Gaetan de Menten <gdemen...@gmail.com> wrote:
from elixir import *
class tt(Entity):
using_options(tablename = 'tt')
d = Field(Integer, primary_key = True)
setup_all()
metadata.bind = 'mysql://localhost/test'
while True:
a = tt.query.filter(None)
for x in a:
print x.d
raw_input('')
a = None
session.expire_all()
Once inserted new records in the table tt by using the command-line
mysql client (and committed), pressing return to loop once shows the
very same set of records, without the newly inserted ones.
On the other hand, note that I found out that moving the metadata.bind
assignment into the while loop does the job. But that means to
reconnect to the engine over and over, which is quite ugly:
from elixir import *
class tt(Entity):
using_options(tablename = 'tt')
d = Field(Integer, primary_key = True)
setup_all()
while True:
metadata.bind = 'mysql://localhost/test'
a = tt.query.filter(None)
for x in a:
print x.d
raw_input('')
Does anyone have a cleaner solution?
Fabien.
this works fine:
write_and_commit.py:
from elixir import *
import time
metadata.bind = "sqlite:///pop.db"
metadata.bind.echo = True
session.configure(autoflush=False)
class Movie(Entity):
title = Field(Unicode(30),primary_key=True)
def __repr__(self):
return '<Movie "%s" (%d)>' % (self.title, self.year)
setup_all(True)
[m.delete() for m in Movie.query.all()]
for i in range(1000):
m=Movie(title=u'pop%d'%i)
session.commit()
time.sleep(3)
sniffer.py:
from elixir import *
import time
metadata.bind = "sqlite:///pop.db"
metadata.bind.echo = False
session.configure(autoflush=False)
class Movie(Entity):
title = Field(Unicode(30),primary_key=True)
def __repr__(self):
return '<Movie "%s">' % (self.title)
setup_all(False)
while True:
time.sleep(1)
print "\n".join(map(str,(Movie.query.all())))
run write_and_commit.py first and then sniffer.py
it works.
--
You received this message because you are subscribed to the Google Groups "SQLElixir" group.
To post to this group, send email to sqle...@googlegroups.com.
To unsubscribe from this group, send email to sqlelixir+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlelixir?hl=en.
That's very strange, because your exact same code works fine here. I
just ran it once with a create_all() after the bind (to create the
table) then removed the line and it works perfectly here.
I've tried with both SA 0.5.x and SA trunk, Elixir 0.6.0, Elixir 0.7.1
and trunk and could not reproduce your problem... I'm out of ideas...
On mysql's side, I've simply done:
mysql> insert into tt values(1);
Query OK, 1 row affected (0.00 sec)
I didn't commit explicitly as it is not needed on the command-line
AFAIK (unless you create a transaction explicitly).
FWIW, here are the versions I have installed:
ii mysql-server-5.1 5.1.37-1ubuntu5
MySQL database server binaries
ii python-mysqldb 1.2.2-10
A Python interface to MySQL
> On the other hand, note that I found out that moving the metadata.bind
> assignment into the while loop does the job. But that means to
> reconnect to the engine over and over, which is quite ugly:
Yeah, quite ugly indeed.
Since this problem is most likely not related to Elixir, you might
want to ask on SQLAlchemy's list.
Thanks a lot for your support, I will post to SQLAlchemy and/or to
mysql-python.
Fabien.