[sqlalchemy] Re: set_shard problems

2008-11-28 Thread Ids

Excellent work! Indeed r5335 did fix the problem. Thank you very much
for your help.

Regards,
Ids

--~--~-~--~~~---~--~~
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: Invalid Request Error at session level.

2008-11-28 Thread Michael Bayer

On Nov 28, 2008, at 1:42 AM, Harish Vishwanath wrote:


 I am guarding my commits with a mutex,

if you are using one session per thread then there is no need to use  
mutexing.


  but the queries are unguarded.

if you are using a single Query object in multiple threads  
simultaneously, that will be problematic, since their usage, as well  
as usage of the objects produced by the Query,  constitutes session  
access, as in when rows are loaded.   Especially if autoflush is  
turned on then you'd essentially be using the Session in a completely  
thread-unsafe manner.


 If one of the session is committing on the database and the other  
 one is trying to query, would this problem arise?

there is no issue with this as long as all Session, Query and  
persistent instance is maintained local to a single thread.   Issues  
at the level of concurrent transaction contention are handled by the  
database (and this error is not related to that).

 I am not very sure on how connection objects are created during this  
 scenario. Appreciate your help.

The Session typically references a single database connection  
throughout the lifespan of a transaction.  when the transaction  
completes, the connection is returned to the pool.

The actual transaction state of the Session is determined by the  
configuration flag autocommit=False as well as the begin()/commit()  
methods.  These are described in the docs.


--~--~-~--~~~---~--~~
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] offline metadata configuration, change storage and metadata snapshot.

2008-11-28 Thread [EMAIL PROTECTED]

Hi All
I'm writing a program for graphically configuring database schemas.
To do this, I want to use the sqlalchemy schema.py objects to store my
metadata as its changed and modified.

To do this, I think i will need three things.
1. Apply the meta data changes to a development database, As this is
the easiest way to ensure integrity as you are reconfiguring the
structure.
2. Store incremental changes to the metadata
3. Snapshot the metadata to a file so it can be restored.

Does SQL Alchemy currently have any facilities to help me achieve
items 2 and 3?

Regards, Jar

--~--~-~--~~~---~--~~
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: offline metadata configuration, change storage and metadata snapshot.

2008-11-28 Thread Michael Bayer


On Nov 28, 2008, at 6:58 AM, [EMAIL PROTECTED] wrote:


 Hi All
 I'm writing a program for graphically configuring database schemas.
 To do this, I want to use the sqlalchemy schema.py objects to store my
 metadata as its changed and modified.

 To do this, I think i will need three things.
 1. Apply the meta data changes to a development database, As this is
 the easiest way to ensure integrity as you are reconfiguring the
 structure.
 2. Store incremental changes to the metadata
 3. Snapshot the metadata to a file so it can be restored.

 Does SQL Alchemy currently have any facilities to help me achieve
 items 2 and 3?


for #1 and #2, you want to use sqlalchemy-migrate at 
http://code.google.com/p/sqlalchemy-migrate/ 
  .   For #3, the metadata object can be pickled, and for more  
sophisticated serilalization of expression and ORM constructs there is  
also a serializer extension in 0.5, documented at 
http://www.sqlalchemy.org/docs/05/plugins.html#plugins_serializer 
.

--~--~-~--~~~---~--~~
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: offline metadata configuration, change storage and metadata snapshot.

2008-11-28 Thread [EMAIL PROTECTED]

Thanks.
I thought of using pickle but it says not everything can be picked, So
i was concerned the metadata objects might be in the unlucky group.
The other problem i have with pickle is what happens when i upgrade to
a newer version of sqlAlchemy some of the metadata objects might
change. How does pickle handle this?
 My other idea instead of pickle was to write code to map it out and
store it in a SQL lite or xml, Then i could patch it so it could be
restored to the never version of sqlAlchemy.

Thanks heaps again for the help,
Regards, Jar

On Nov 29, 1:56 am, Michael Bayer [EMAIL PROTECTED] wrote:
 On Nov 28, 2008, at 6:58 AM, [EMAIL PROTECTED] wrote:



  Hi All
  I'm writing a program for graphically configuring database schemas.
  To do this, I want to use the sqlalchemy schema.py objects to store my
  metadata as its changed and modified.

  To do this, I think i will need three things.
  1. Apply the meta data changes to a development database, As this is
  the easiest way to ensure integrity as you are reconfiguring the
  structure.
  2. Store incremental changes to the metadata
  3. Snapshot the metadata to a file so it can be restored.

  Does SQL Alchemy currently have any facilities to help me achieve
  items 2 and 3?

 for #1 and #2, you want to use sqlalchemy-migrate 
 athttp://code.google.com/p/sqlalchemy-migrate/
   .   For #3, the metadata object can be pickled, and for more
 sophisticated serilalization of expression and ORM constructs there is
 also a serializer extension in 0.5, documented 
 athttp://www.sqlalchemy.org/docs/05/plugins.html#plugins_serializer
 .
--~--~-~--~~~---~--~~
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] New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat

2008-11-28 Thread Doug Farrell

Hi all,

I'm having a problem with a new instance of a relation conflicting with
an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my
simplified classes:

class Stat(sqladb.Base):
__tablename__ = stats
name = Column(String(32), primary_key=True)
total= Column(Integer)
created  = Column(DateTime, default=datetime.datetime.now())
updated  = Column(DateTime)
states   = Column(PickleType, default={})
extraStats   = relation(ExtraStat, backref=stat)

class ExtraStat(sqladb.Base):
__tablename__ = extrastats
name = Column(String(32), ForeignKey(stats.name),
primary_key=True)
total= Column(Integer)
created  = Column(DateTime, default=datetime.datetime.now())
updated  = Column(DateTime)
states   = Column(PickleType, default={})

The above Stat class has a one-to-many relationship with the ExtraStat
class (which I think I've implemented correctly). Later in the program I
create an in memory data model that has as part of it's components two
dictionaries that contain Stat instances. Those Stat instances have
relationships to ExtraStat instances. My problem comes in the following
when I'm trying to update the data in those instances/tables. Here is a
section of code that throws the exception:

pressName = press%s % pressNum
# add new ExtraStat instances as relations
self._addProductStatsPress(productType, pressName)
self._addPressStatsProduct(pressName, productType)
try:
  extraStat = session.query(Stat). \
  filter(Stat.name==productType). \
  join(extraStats). \
  filter(ExtraStat.name==pressName).one()
except:
  extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE)
  self.productStats[productType].extraStats.append(extraStat)
  extraStat.states.setdefault(sstate, 0)
  extraStat.states[sstate] += 1
  extraStat.updated = now
  extraStat = session.merge(extraStat)
try:
  extraStat = session.query(Stat). \
  filter(Stat.name==pressName). \
  join(extraStats). \
  filter(ExtraStat.name==productType).one()    throws
exception right here
except:
  extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE)
  self.pressStats[pressName].extraStats.append(extraStat)
  extraStat.states.setdefault(sstate, 0)
  extraStat.states[sstate] += 1
  extraStat.updated = now

The marked area is wear it throws the exception. I'm not sure what to do
here to get past this, any help or ideas would be greatly appreciated.

The exact exception is as follows:
Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity
key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent
instance [EMAIL PROTECTED]

Thanks!
Doug  

--~--~-~--~~~---~--~~
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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat

2008-11-28 Thread King Simon-NFHD78

 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:[EMAIL PROTECTED] On Behalf Of Doug Farrell
 Sent: 28 November 2008 18:22
 To: sqlalchemy@googlegroups.com
 Subject: [sqlalchemy] New instance ExtraStat with identity 
 key (...) conflicts with persistent instance ExtraStat
 
 
 Hi all,
 
 I'm having a problem with a new instance of a relation 
 conflicting with
 an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my
 simplified classes:
 
 class Stat(sqladb.Base):
 __tablename__ = stats
 name = Column(String(32), primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})
 extraStats   = relation(ExtraStat, backref=stat)
 
 class ExtraStat(sqladb.Base):
 __tablename__ = extrastats
 name = Column(String(32), ForeignKey(stats.name),
 primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})
 
 The above Stat class has a one-to-many relationship with the ExtraStat
 class (which I think I've implemented correctly). Later in 
 the program I
 create an in memory data model that has as part of it's components two
 dictionaries that contain Stat instances. Those Stat instances have
 relationships to ExtraStat instances. My problem comes in the 
 following
 when I'm trying to update the data in those instances/tables. 
 Here is a
 section of code that throws the exception:
 
 pressName = press%s % pressNum
 # add new ExtraStat instances as relations
 self._addProductStatsPress(productType, pressName)
 self._addPressStatsProduct(pressName, productType)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==productType). \
   join(extraStats). \
   filter(ExtraStat.name==pressName).one()
 except:
   extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE)
   self.productStats[productType].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now
   extraStat = session.merge(extraStat)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==pressName). \
   join(extraStats). \
   filter(ExtraStat.name==productType).one()    throws
 exception right here
 except:
   extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE)
   self.pressStats[pressName].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now
 
 The marked area is wear it throws the exception. I'm not sure 
 what to do
 here to get past this, any help or ideas would be greatly appreciated.
 
 The exact exception is as follows:
 Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] 
 With identity
 key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent
 instance [EMAIL PROTECTED]
 
 Thanks!
 Doug  
 

This may not be the cause of your problem, but with your mapping above,
I think you can only have one ExtraStat per Stat, because they have the
same primary key (the 'name' column). If 'name' is the only thing that
uniquely distinguishes an ExtraStat, you can only have one per name.

Hope that helps,

Simon

--~--~-~--~~~---~--~~
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] query.with_polymorphic()

2008-11-28 Thread az

what should query.with_polymorphic generate?
e.g. given query(A).with_polymorphic( B,D)
it does something like 
select ... 
from A left outer join B left outer join D

and no discriminator filter..

which includes all A's regardless of their type...

svil

--~--~-~--~~~---~--~~
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: query.with_polymorphic()

2008-11-28 Thread Michael Bayer

with_polymorphic doesn't limit what classes are loaded.  It only  
controls how the SQL is rendered such that fewer subsequent queries  
are needed when attributes are referenced on the resulting objects,  
and also so that you can specify filtering criterion on those joined  
tables.

On Nov 28, 2008, at 3:51 PM, [EMAIL PROTECTED] wrote:


 what should query.with_polymorphic generate?
 e.g. given query(A).with_polymorphic( B,D)
 it does something like
 select ...
 from A left outer join B left outer join D

 and no discriminator filter..

 which includes all A's regardless of their type...

 svil

 


--~--~-~--~~~---~--~~
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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat

2008-11-28 Thread [EMAIL PROTECTED]

What was your justification of changing the name of my thread to a
completely different topic instead of starting a new thread?

I don't think thats good etiquette.


On Nov 29, 5:22 am, Doug Farrell [EMAIL PROTECTED] wrote:
 Hi all,

 I'm having a problem with a new instance of a relation conflicting with
 an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my
 simplified classes:

 class Stat(sqladb.Base):
 __tablename__ = stats
 name = Column(String(32), primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})
 extraStats   = relation(ExtraStat, backref=stat)

 class ExtraStat(sqladb.Base):
 __tablename__ = extrastats
 name = Column(String(32), ForeignKey(stats.name),
 primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})

 The above Stat class has a one-to-many relationship with the ExtraStat
 class (which I think I've implemented correctly). Later in the program I
 create an in memory data model that has as part of it's components two
 dictionaries that contain Stat instances. Those Stat instances have
 relationships to ExtraStat instances. My problem comes in the following
 when I'm trying to update the data in those instances/tables. Here is a
 section of code that throws the exception:

 pressName = press%s % pressNum
 # add new ExtraStat instances as relations
 self._addProductStatsPress(productType, pressName)
 self._addPressStatsProduct(pressName, productType)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==productType). \
   join(extraStats). \
   filter(ExtraStat.name==pressName).one()
 except:
   extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE)
   self.productStats[productType].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now
   extraStat = session.merge(extraStat)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==pressName). \
   join(extraStats). \
   filter(ExtraStat.name==productType).one()    throws
 exception right here
 except:
   extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE)
   self.pressStats[pressName].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now

 The marked area is wear it throws the exception. I'm not sure what to do
 here to get past this, any help or ideas would be greatly appreciated.

 The exact exception is as follows:
 Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity
 key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent
 instance [EMAIL PROTECTED]

 Thanks!
 Doug
--~--~-~--~~~---~--~~
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: New instance ExtraStat with identity key (...) conflicts with persistent instance ExtraStat

2008-11-28 Thread [EMAIL PROTECTED]

What was your justification of changing the name of my thread to a
completely different topic instead of starting a new thread?

I don't think thats good etiquette.


On Nov 29, 5:22 am, Doug Farrell [EMAIL PROTECTED] wrote:
 Hi all,

 I'm having a problem with a new instance of a relation conflicting with
 an existing instance. I'm using SA 0.5rc with Sqlite3. Here are my
 simplified classes:

 class Stat(sqladb.Base):
 __tablename__ = stats
 name = Column(String(32), primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})
 extraStats   = relation(ExtraStat, backref=stat)

 class ExtraStat(sqladb.Base):
 __tablename__ = extrastats
 name = Column(String(32), ForeignKey(stats.name),
 primary_key=True)
 total= Column(Integer)
 created  = Column(DateTime, default=datetime.datetime.now())
 updated  = Column(DateTime)
 states   = Column(PickleType, default={})

 The above Stat class has a one-to-many relationship with the ExtraStat
 class (which I think I've implemented correctly). Later in the program I
 create an in memory data model that has as part of it's components two
 dictionaries that contain Stat instances. Those Stat instances have
 relationships to ExtraStat instances. My problem comes in the following
 when I'm trying to update the data in those instances/tables. Here is a
 section of code that throws the exception:

 pressName = press%s % pressNum
 # add new ExtraStat instances as relations
 self._addProductStatsPress(productType, pressName)
 self._addPressStatsProduct(pressName, productType)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==productType). \
   join(extraStats). \
   filter(ExtraStat.name==pressName).one()
 except:
   extraStat = ExtraStat(pressName, ExtraStat.PRESS_TYPE)
   self.productStats[productType].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now
   extraStat = session.merge(extraStat)
 try:
   extraStat = session.query(Stat). \
   filter(Stat.name==pressName). \
   join(extraStats). \
   filter(ExtraStat.name==productType).one()    throws
 exception right here
 except:
   extraStat = ExtraStat(productType, ExtraStat.PRODUCT_TYPE)
   self.pressStats[pressName].extraStats.append(extraStat)
   extraStat.states.setdefault(sstate, 0)
   extraStat.states[sstate] += 1
   extraStat.updated = now

 The marked area is wear it throws the exception. I'm not sure what to do
 here to get past this, any help or ideas would be greatly appreciated.

 The exact exception is as follows:
 Sqlalchemy.orm.exc.FlushError: New instance [EMAIL PROTECTED] With identity
 key (class '__main__.ExtraStat',(u'C',)) conflicts with persistent
 instance [EMAIL PROTECTED]

 Thanks!
 Doug
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---