[sqlalchemy] odict for mapper properties?

2009-10-19 Thread Gaetan de Menten

Hi Mike,

I see in r6413, that you use an ordered dictionary instead of a
standard one for properties, in an attempt to fix some jython
ordering annoyingness. Is this really necessary to be compliant with
Jython? Would you care to explain? I'm quite puzzled as to how that
change could have any effect...

Thanks in advance,
-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: odict for mapper properties?

2009-10-19 Thread Michael Bayer

Gaetan de Menten wrote:

 Hi Mike,

 I see in r6413, that you use an ordered dictionary instead of a
 standard one for properties, in an attempt to fix some jython
 ordering annoyingness. Is this really necessary to be compliant with
 Jython? Would you care to explain? I'm quite puzzled as to how that
 change could have any effect...

that particular odict is only within the context of a particular unit test
which is looking for an exact SQL statement to be rendered based on that
mapper.   the depending on the order of the address and orders
attribute (if i recall correctly the names), its the difference between:

select address.foo, address.bar, orders.foo, orders.bar, ...

and

select orders.foo, orders.bar, address.foo, address.bar, ...

i.e. it doesn't make any difference except for a test that is testing for
an exact SQL string.

dictionary ordering changes based on platform and implementation.  In this
case those two attributes got reversed when run on Jython.   the mapper's
internal dictionary of properties is ordered in any case, in this case its
just the dictionary used to pass the argument in within the test.







 Thanks in advance,
 --
 Gaëtan de Menten
 http://openhex.org

 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] License of the example files

2009-10-19 Thread Yannick Gingras

Greetings Alchemists, 
  I plan to base a chunk of my code on one of the examples in
sqlalchemy/examples.  I just want to make sure that those are free to
use.  SQLAlchemy is licenced under the X11 (MIT) license.  Is it also
the case for the examples?

-- 
Yannick Gingras
http://ygingras.net
http://confoo.ca -- track coordinator
http://montrealpython.org -- lead organizer


signature.asc
Description: This is a digitally signed message part.


[sqlalchemy] Re: License of the example files

2009-10-19 Thread Michael Bayer

Yannick Gingras wrote:

 Greetings Alchemists,
   I plan to base a chunk of my code on one of the examples in
 sqlalchemy/examples.  I just want to make sure that those are free to
 use.  SQLAlchemy is licenced under the X11 (MIT) license.  Is it also
 the case for the examples?

it is !   tell Bill Gates I said hi.




 --
 Yannick Gingras
 http://ygingras.net
 http://confoo.ca -- track coordinator
 http://montrealpython.org -- lead organizer



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: odict for mapper properties?

2009-10-19 Thread Gaetan de Menten

On Mon, Oct 19, 2009 at 16:04, Michael Bayer mike...@zzzcomputing.com wrote:

 I see in r6413, that you use an ordered dictionary instead of a
 standard one for properties, in an attempt to fix some jython
 ordering annoyingness. Is this really necessary to be compliant with
 Jython? Would you care to explain? I'm quite puzzled as to how that
 change could have any effect...

 i.e. it doesn't make any difference except for a test that is testing for
 an exact SQL string.

Doh! Should have looked at the test in question, that'd have been
obvious. Sorry about this.
-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: invalid transaction rollback etc and making a join join

2009-10-19 Thread Jeff Cook

I removed SQLSoup and the caching/stale results issues are gone now.
Have to wait a little longer to see if there is any bearing on the
MySQL has gone away/invalid transaction thing.

Changing the default beaker timeout to something small, like 15 secs,
doesn't seem to fix things.

Thanks for all the help everyone.

On Sat, Oct 17, 2009 at 8:08 PM, cd34 mcd...@gmail.com wrote:

 On Oct 17, 6:49 pm, Jeff Cook cookieca...@gmail.com wrote:
 Unfortunately, from a support-seeker point of view, such rhetoric is
 often necessary. How many times have you written a mailing list or hit

 sqlalchemy.pool_recycle = 10

 I had odd issues -- even though mysql was set to

 | interactive_timeout     | 60    |
 | net_read_timeout        | 30    |
 | net_write_timeout       | 60    |
 | slave_net_timeout       | 3600  |
 | table_lock_wait_timeout | 50    |
 | wait_timeout            | 60    |

 A request that was valid and executed once before had problems when
 pool_recycle was = 30 with pylons.

 In project/model/meta.py

 I set

 Session = scoped_session(sessionmaker(autocommit=True))

 which eliminated the situation where the transaction error required
 restarting paster.  Setting this is a bad thing, but then you can see
 if the issue is within the sql and your translation to sqlalchemy, or,
 whether it is something external.  This prevents the inevitable pylons
 'hangup' when you get the sqlalchemy error reported in pylons and have
 to restart the server to continue debugging.

 As for caching, you might doublecheck your beaker settings to turn it
 off while testing.  I haven't seen pylons excessively cache with their
 default site template.
 


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Sessions, threads, TurboGears best practice?

2009-10-19 Thread thatsanicehatyouhave

Hi,

I'm hoping someone can help me with properly configuring a session/ 
transactions for multiple uses as I haven't been able to get it quite  
right.

I've created a python module to contain my model classes and a  
connection class. This module wil be imported by both single-use  
scripts (run, then quit), long-running background scripts (run  
passively while waiting for a new event), and imported into a  
TurboGears app. I'm using PostgreSQL 8.4, SQLAlchemy 0.5.5, and  
TurboGears 2.0.

After getting different types of transaction errors, e.g.

 InternalError: (InternalError) current transaction is aborted,  
 commands ignored until end of transaction block

 InvalidRequestError:  Can't reconnect until invalid transaction is  
 rolled back

 A transaction is already begun.  Use subtransactions=True 
 sqlalchemy.exc.InvalidRequestError: A transaction is already begun.  
 Use subtransactions=True to allow subtransactions.

I settled on this in my db connection module, which is called by all  
my scripts:

class MyDatabase:

def __init__(self, database_connection_string=None):

self.database_connection_string = database_connection_string
self.engine = create_engine(self.database_connection_string,  
echo=False)
self.metadata = MetaData()
self.metadata.bind = self.engine

try:
db # singleton
except NameError:
db = MyDatabase()
engine = db.engine
metadata = db.metadata
Session = scoped_session(sessionmaker(bind=engine, autocommit=True,  
autoflush=False))


Then in each script I import this module, create a new session:

session = Session()

and query like this:

if session.autocommit:
session.begin()
do stuff that modifies the db, i.e. not just select statements
session.commit()


I was hoping this is fairly bullet-proof, but unfortunately my  
TurboGears app still hangs (with no error messages) after running for  
some period of time, though I think it hangs when multiple queries hit  
the database at the same time. I'm suspecting some kind of deadlock,  
but that's just a guess.

I'm at a loss as to where the problem lies, but I wanted to check with  
the experts here that I'm using SA appropriately. Any help/suggestions  
greatly appreciated.

Cheers,
Demitri


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Synchronization problem at backref of a one-to-many relation to the same class.

2009-10-19 Thread Tefnet Developers

Dnia 2009-10-08, czw o godzinie 11:16 -0400, Michael Bayer pisze:
 Tefnet Developers wrote:
 
  Dnia 2009-10-08, czw o godzinie 09:59 -0400, Michael Bayer pisze:
   Is this a SQLAlchemy bug or my mistake?
 
  Backrefs deal with the two-way relation between A-B, but the event
  does
  not propagate in most cases to C or beyond, i.e. A-B-C where B is
  attached to A would indicate C-B becomes detached in memory.  After a
  commit() all those references would be expired and then you'd see the
  actual connections.

Yes, sorry, I had a mistake in my test and in fact the behaviour is
consistent. I have just created my own AttributeExtension which handles
these situations. Thanks for clarifying things out :).

regards,
Filip Zyzniewski
Tefnet


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] using ORM in AttributeExtension

2009-10-19 Thread Tefnet Developers

Hi,

and here comes another problem with my project utilizing SQLAlchemy :).

I am trying to use ORM in AttributeExtension:
(http://dpaste.com/109454/)
=
import sqlalchemy
import sqlalchemy.ext.declarative

Base = sqlalchemy.ext.declarative.declarative_base(mapper =
sqlalchemy.orm.mapper)

engine = sqlalchemy.create_engine('sqlite:///:memory:', echo = False)

session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind
= engine))

Base.metadata.bind = engine

class AttrEx(sqlalchemy.orm.interfaces.AttributeExtension):
def set(self, state, value, oldvalue, initiator):
for o in session.query(Foo):
pass
return value

class Foo(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer, primary_key =
True, autoincrement  =True)
__tablename__ = 'foo'

class Bar(Base):
Id = sqlalchemy.Column(sqlalchemy.types.Integer, primary_key=True,
autoincrement = True)
someAttr =
sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer), 
extension = AttrEx())
__tablename__ = 'bar'
   
Base.metadata.create_all()

a = Bar()
session.add(a)
a.someAttr = 5
assert a.someAttr == 5
session.commit()
assert a.someAttr == 5
=

Seccond assert explodes. It seems that query'ing in AttrEx's set()
method triggers flush (autoflush which I need) and somehow value
returned by set() gets lost. Is there a correct way to manipulate other
mapped objects in AttributeExtensions?

regards,
Filip Zyznieski
Tefnet


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] purpose of class_mapper

2009-10-19 Thread strattonbrazil

What is the purpose of class_mapper?  I can't find it in the .4 docs
for the tutorials I'm looking at, yet when I don't call it as

https://svn.enthought.com/svn/enthought/sandbox/EnvisageSQLAlchemy/enthought/sqlalchemy/has_traits_orm.py

notes, I get a

AttributeError:
# 'ColumnProperty' object has no attribute 'key'

Is my setup incorrect that causes me to need class_mapper, while the .
4 docs don't include it?  Or am I doing something different enough
from the tutorials to require it?

I'm running
Python: 2.5.1
sqlite: 2.3.2
sqlalchemy 0.4.8

# create the database file and associated tables
statsFile = Path('./stats.db')
engine = create_engine('sqlite:///' + statsFile,
echo=False)
conn = engine.connect()
metadata = MetaData(engine)
self.createStatsTables(metadata)
metadata.create_all(engine) # save tables (up to here
works by looking at the database outside python using the sqlite3
command tool

Session.configure(bind=engine)
session = Session()

class User(object):
self.userName = ''
user = User()
user.userName = 'Joe'
mapper(User, usersTable)
class_mapper(User) # if I don't add this to the
tutorial code, I get the error
session.save(user)

session.commit()
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: purpose of class_mapper

2009-10-19 Thread Michael Bayer

strattonbrazil wrote:

 What is the purpose of class_mapper?  I can't find it in the .4 docs
 for the tutorials I'm looking at, yet when I don't call it as

 https://svn.enthought.com/svn/enthought/sandbox/EnvisageSQLAlchemy/enthought/sqlalchemy/has_traits_orm.py

 notes, I get a

 AttributeError:
 # 'ColumnProperty' object has no attribute 'key'

that is an ancient bug which refers to the fact that mappers have not been
compiled, yet an expression is doing something along the lines of
User.some_property == somevalue.   The Class.descriptor expression
approach was new in 0.4 and had some incompleteness.

To work around it in 0.4 the most general way is to call
compile_mappers().   class_mapper() also has the effect of invoking a
compile if the mapper being returned was not yet compiled. 
class_mapper() in modern SQLAlchemy would normally only be used if
additional configuration needs to be added to an existing mapper, given
only a class.




--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---