[sqlalchemy] Failures with AssociationProxy (starting with r2598)
Starting with r2598, I'm seeing some failures with how I'm using the association proxy. I've modified the examples/association/proxied_association.py file which duplicates the problem. It is possible that I'm not suppose to remove associations like I am. But it did work before (in 0.3.7 and 0.3.6). It looks like if I read in part of the association into the current session and then delete it, things don't go so well. Index: examples/association/proxied_association.py === --- examples/association/proxied_association.py (revision 2723) +++ examples/association/proxied_association.py (working copy) @@ -106,8 +106,18 @@ +# new additions to proxied_association.py +#engine.echo = True +new_item = Item('new item', 100) +session.clear() +order = session.query(Order).get_by(customer_name='john smith') +bogus = order.items[0].item_id # comment out and it works on 0.3.8 +order.itemassociations = None +session.flush() +order.items.append(new_item) +session.flush() It fails with: sqlalchemy.exceptions.SQLError: (IntegrityError) orderitems.order_id may not be NULL u'INSERT INTO orderitems (item_id, price) VALUES (?, ?)' [5, 100] Thanks, Paul --~--~-~--~~~---~--~~ 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: Failures with AssociationProxy (starting with r2598)
Ive added ticket #597 for this. On Jun 12, 2:22 am, Paul Kippes [EMAIL PROTECTED] wrote: Starting with r2598, I'm seeing some failures with how I'm using the association proxy. I've modified the examples/association/proxied_association.py file which duplicates the problem. It is possible that I'm not suppose to remove associations like I am. But it did work before (in 0.3.7 and 0.3.6). It looks like if I read in part of the association into the current session and then delete it, things don't go so well. Index: examples/association/proxied_association.py === --- examples/association/proxied_association.py (revision 2723) +++ examples/association/proxied_association.py (working copy) @@ -106,8 +106,18 @@ +# new additions to proxied_association.py +#engine.echo = True +new_item = Item('new item', 100) +session.clear() +order = session.query(Order).get_by(customer_name='john smith') +bogus = order.items[0].item_id # comment out and it works on 0.3.8 +order.itemassociations = None +session.flush() +order.items.append(new_item) +session.flush() It fails with: sqlalchemy.exceptions.SQLError: (IntegrityError) orderitems.order_id may not be NULL u'INSERT INTO orderitems (item_id, price) VALUES (?, ?)' [5, 100] Thanks, Paul --~--~-~--~~~---~--~~ 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: Failures with AssociationProxy (starting with r2598)
Would you write a failing test for this condition? I looked at the unit tests but wasn't able to make a failing test. So that is why I modified the example. I also tried to formulate a work around. And failed at that as well. On 6/12/07, Michael Bayer [EMAIL PROTECTED] wrote: Ive added ticket #597 for this. On Jun 12, 2:22 am, Paul Kippes [EMAIL PROTECTED] wrote: Starting with r2598, I'm seeing some failures with how I'm using the association proxy. I've modified the examples/association/proxied_association.py file which duplicates the problem. It is possible that I'm not suppose to remove associations like I am. But it did work before (in 0.3.7 and 0.3.6). It looks like if I read in part of the association into the current session and then delete it, things don't go so well. Index: examples/association/proxied_association.py === --- examples/association/proxied_association.py (revision 2723) +++ examples/association/proxied_association.py (working copy) @@ -106,8 +106,18 @@ +# new additions to proxied_association.py +#engine.echo = True +new_item = Item('new item', 100) +session.clear() +order = session.query(Order).get_by(customer_name='john smith') +bogus = order.items[0].item_id # comment out and it works on 0.3.8 +order.itemassociations = None +session.flush() +order.items.append(new_item) +session.flush() It fails with: sqlalchemy.exceptions.SQLError: (IntegrityError) orderitems.order_id may not be NULL u'INSERT INTO orderitems (item_id, price) VALUES (?, ?)' [5, 100] Thanks, Paul --~--~-~--~~~---~--~~ 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: Failures with AssociationProxy (starting with r2598)
On Jun 12, 2007, at 11:13 AM, Paul Kippes wrote: Would you write a failing test for this condition? I looked at the unit tests but wasn't able to make a failing test. So that is why I modified the example. I also tried to formulate a work around. And failed at that as well. we have a highly skilled SA team member, who has taken the role of enhancing SA's various collection magic, who is going to fix this bug so well there'll be no trace it ever happened. we can make a test based on what you've illustrated in the example. --~--~-~--~~~---~--~~ 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: PROPOSAL: whack query.select(), selectfirst(), selectone(), select_by(), selectfirst_by(), selectone_by(), get_by(), auto-join feature
Cleaning out my inbox... FWIW I'm +1 on removing the old-style methods, +1 on .first instead of .scalar, +1 on adding .one, and +0 on renaming .list to .all. Did you make a decision for 0.4 Mike? -J --~--~-~--~~~---~--~~ 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: PROPOSAL: whack query.select(), selectfirst(), selectone(), select_by(), selectfirst_by(), selectone_by(), get_by(), auto-join feature
On 6/12/07, Michael Bayer [EMAIL PROTECTED] wrote: we have, in fact, made a tip of the hat to SAT analogy questions (selecting everything is to all() as selecting just the first row is to: a. scalar() b. first() c. list()[0]). I've already said it earlier but since you didn't comment on that, maybe you didn't see my remark: shouldn't the non-generative aggregate methods be deprecated? I feek it would be much more coherent this way. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Query.get with unordered multiple-column-primary-key
Hi, Anybody knows how I could emulate the behavior of Query.get (ie get the result from the session if possible instead of always fetching from the db) if I have the values for the different columns of the primary as keyword arguments (ie not in the order of the columns of the initial table)? I need a kind of a mix between get_by and get. Any idea? -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dictionaries collection_class
the legal way is the association_proxy and family. here another shorter ... a hack: i did have similar need - obj.somerelation.append( left=.., right=..), so i did monkeypatch the InstrumentedList's append to use the item returned from collection's append - def append( self, *args, **kwargs): item = self._data_appender( *args,**kwargs) self._InstrumentedList__setrecord( item) #private __setrecord; was _before_ _data_appender sqlalchemy.orm.attributes.InstrumentedList.append = append and use my own collection which creates the association object from append's keywordargs, then factory for it and give that to collection_class= of relation() class Association: 'base for all assoc_klas' class MyCollection( list): factory = None def append( me, obj =_Relation, **kargs): if obj is _Relation:#just marker for notset obj = me.factory( **kargs) list.append( me, obj) return obj @classmethod def myCollectionFactory( klas): m = Association.MyCollection() m.factory = klas#the assoc-obj-type return m mapper ( ... relation( collection_class = assoc_klas.myCollectionFactory ) ) --- u'll have to do it over __setitem__. have fun. svil On Tuesday 12 June 2007 21:26:52 Ron wrote: I have an object that has a relation to an Attributes table. The Attributes table is just key/value pairs with a pointer to the object in the main table. I'd like to make the use of my object very simple by exposing these object attributes as a dictionary. So, I'd like to be able to do this: obj.attrs['foo'] = 'a' instead of obj.attrs.append(Attribute('foo', 'a')) The documentation has an example for using the collection_class argument to relation() but in order to make things actually work as above I think I'd need to override __setitem__ but that sqlalchemy doesn't seem to let me do that. What am I missing? -Ron --~--~-~--~~~---~--~~ 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: Problems with non existing relations
actually, I am iterating through all the databases in the meta ti = model.meta.table_iterator() for t in ti: print create %s ? % t if raw_input(Choose [Y/n]).lower() in ['y','']: t.create() I want to be able to chose which database to create from a pool on database models On Jun 12, 8:47 pm, Michael Bayer [EMAIL PROTECTED] wrote: youre going to want to access your metadata object and say metadata.create_all(). you have a users table that hasnt been created in your database upon which your user_roles table depends. --~--~-~--~~~---~--~~ 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: dictionaries collection_class
Using the association_proxy extension in combination with your dictionary collection class is an easy way to get this kind of simplified access. Assuming your Attribute's value is in a property called 'value', you can set up simple dict access like so: class Obj(object): attrs = association_proxy('_attrs', 'value') mapper(Obj, ..., properties = { '_attrs': relation(Attribute, collection_class=your_dict_class) } obj.attrs['foo'] = 'a' -jek When I try the above I get this error at flush time: InvalidRequestError: Class 'str' entity name 'None' has no mapper associated with it Here is my dictionary collection_class: class AttributeDictNEW(dict): My Attribute Dict def append(self, item): super(AttributeDictNEW, self).__setitem__(item.name, item) def test__iter__(self): return iter(self.values()) def test__getitem__(self, name): return super(AttributeDictNEW, self).__getitem__(name).value def __setitem__(self, name, value): if not isinstance(value, Attribute): newattr = Attribute(name, str(value)) self.append(newattr) else: self.append(value) The test__ functions are named such to get out of the way of the parent class's functions while testing. I may be misunderstanding how an association_proxy works. -Ron --~--~-~--~~~---~--~~ 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: dictionaries collection_class
Ron wrote: When I try the above I get this error at flush time: InvalidRequestError: Class 'str' entity name 'None' has no mapper associated with it Here is my dictionary collection_class: class AttributeDictNEW(dict): My Attribute Dict def append(self, item): super(AttributeDictNEW, self).__setitem__(item.name, item) def test__iter__(self): return iter(self.values()) def test__getitem__(self, name): return super(AttributeDictNEW, self).__getitem__(name).value def __setitem__(self, name, value): if not isinstance(value, Attribute): newattr = Attribute(name, str(value)) self.append(newattr) else: self.append(value) The test__ functions are named such to get out of the way of the parent class's functions while testing. The association proxy will take care of Attribute construction for you, so you can get away with just: class AttributeDictNEW(dict): def append(self, item): self[item.key] = item def __iter__(self): return self.itervalues() However, newattr = Attribute(name, str(value)) For the stringification of values on construction, you can either do that in Attribute's __init__ or supply a creator function to the association proxy: stringy_attr = lambda name, value: Attribute(name, str(value)) ... attrs = association_proxy('_attrs', 'value', creator=stringy_attr) -jek --~--~-~--~~~---~--~~ 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: dictionaries collection_class
The association proxy will take care of Attribute construction for you, so you can get away with just: class AttributeDictNEW(dict): def append(self, item): self[item.key] = item def __iter__(self): return self.itervalues() So now I if I try to get something from the dict: obj.attr['foo'] I get this error: KeyError: schema.Attribute object at 0xb78a8e0c ok, so it looks like something is turning 'foo' into an Attribute. Fine, so I add this to the AttributeDictNEW: def __getitem__(self, item): return super(AttributeDictNEW, self).__getitem__(item.name) But I get: return super(AttributeDictNEW, self).__getitem__(item.name) AttributeError: 'str' object has no attribute 'name' if I do a sys.stderr.write(str(type(item))) before the return it outputs this: class 'schema.Attribute' item is an Attribute, but the error indicates it's a str that doesn't have a 'name' member variable. So I'm totally confused. -Ron --~--~-~--~~~---~--~~ 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] ONLY NOW! Special price bid - you can buy new web page on HALF price!!!
I do not want to cheat anybody. I'm a student and made that web page in my spare time. My web page GPCapitalGroup.com has spent about 100 hours and my direct costs reach approximatelly $200 only for buying webhosting and domain. In case, you would like to buy that web page with or without domain and webhosting, go to eBay: http://cgi.ebay.com/Net-Business-Turn-Your-Idea-into-Reality-and-Get-Rich_W0QQitemZ200117009340QQihZ010QQcategoryZ50972QQssPageNameZWDVWQQrdZ1QQcmdZViewItem G.P. --~--~-~--~~~---~--~~ 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] mssql reflection NoSuchTableError
Hello all I am experimenting with SA on MSSQL and am having difficulty with table reflection as outlined in the tutorial, for instance: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/db') metadata = BoundMetaData(db) users_table = Table('users', metadata, Column('user_id', Integer, primary_key=True), Column('user_name', String(40)), Column('password', String(10)) ) metadata.engine.echo = True users_table.create() All of this works fine, it creates the 'users' table no problem, but if I come back and try this it returns a NoSuchTableError: users = Table('users', metadata, autoload=True) Traceback (most recent call last): File pyshell#3, line 1, in -toplevel- users = Table('users', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: users With a little searching around I also tried the schema='' argument and the owner='' argument on Table() with the same error. I tried the exact same thing on mysql and it worked perfectly. There must be something obvious that I am doing wrong here, or something specific to mssql, any tips? (This is MSSQL2000 server + pymssql on a windows client, python 2.4.2 btw) Thanks in advance --~--~-~--~~~---~--~~ 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: mssql reflection NoSuchTableError
Just tried it here on a Linux + pymssql box and it worked fine. The 'NoSuchTable' error would indicate that the table is not found, as you surmised. Check to make sure the table is really persisting after your first session with the table create. In the meantime, I'll see if I can get pymssql running on Windows to see if I can replicate the problem here. Rick On 6/12/07, one.person [EMAIL PROTECTED] wrote: Hello all I am experimenting with SA on MSSQL and am having difficulty with table reflection as outlined in the tutorial, for instance: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/db') metadata = BoundMetaData(db) users_table = Table('users', metadata, Column('user_id', Integer, primary_key=True), Column('user_name', String(40)), Column('password', String(10)) ) metadata.engine.echo = True users_table.create() All of this works fine, it creates the 'users' table no problem, but if I come back and try this it returns a NoSuchTableError: users = Table('users', metadata, autoload=True) Traceback (most recent call last): File pyshell#3, line 1, in -toplevel- users = Table('users', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: users With a little searching around I also tried the schema='' argument and the owner='' argument on Table() with the same error. I tried the exact same thing on mysql and it worked perfectly. There must be something obvious that I am doing wrong here, or something specific to mssql, any tips? (This is MSSQL2000 server + pymssql on a windows client, python 2.4.2 btw) Thanks in advance --~--~-~--~~~---~--~~ 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: mssql reflection NoSuchTableError
one.person View profile More options Jun 12, 5:12 pm From: one.person [EMAIL PROTECTED] Date: Wed, 13 Jun 2007 00:12:50 - Local: Tues, Jun 12 2007 5:12 pm Subject: Re: mssql reflection NoSuchTableError Reply | Reply to author | Forward | Print | Individual message | Show original | Remove | Report this message | Find messages by this author Thanks for the quick reply, I have additional info after more experimentation. This works fine in a single python session as shown: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/dbname') metadata = BoundMetaData(db) z_table = Table('z_table', metadata, Column('col1', Integer), Column('col2', String(20)) ) z_table.create() z_table_test = Table('z_table', metadata, autoload=True) [c.name for c in z_table_test.columns] ['col1', 'col2'] However, if I shut down python and start a new session (I am using IDLE btw), it will not pick up the table it just created: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/dbname') metadata = BoundMetaData(db) z_table_test = Table('z_table', metadata, autoload=True) Traceback (most recent call last): File pyshell#3, line 1, in -toplevel- z_table_test = Table('z_table', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: z_table Consequently when I do the above I cannot reflect any of the pre- existing tables in the database. When I check the database itself 'z_table' really does exist and I can query it in Query Analyzer and modify it in Enterprise Manager. Thanks again for your 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: mssql reflection NoSuchTableError
Works in Windows, too, sqlalchemy 0.3.8, Python 2.5, pymssql 0.8.0, MSSQL 2005 Try upgrading your pymssql if you're not at 0.8.0. If that won't work, then I would suggest a switch to pyodbc Rick On 6/12/07, one.person [EMAIL PROTECTED] wrote: one.person View profile More options Jun 12, 5:12 pm From: one.person [EMAIL PROTECTED] Date: Wed, 13 Jun 2007 00:12:50 - Local: Tues, Jun 12 2007 5:12 pm Subject: Re: mssql reflection NoSuchTableError Reply | Reply to author | Forward | Print | Individual message | Show original | Remove | Report this message | Find messages by this author Thanks for the quick reply, I have additional info after more experimentation. This works fine in a single python session as shown: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/dbname') metadata = BoundMetaData(db) z_table = Table('z_table', metadata, Column('col1', Integer), Column('col2', String(20)) ) z_table.create() z_table_test = Table('z_table', metadata, autoload=True) [c.name for c in z_table_test.columns] ['col1', 'col2'] However, if I shut down python and start a new session (I am using IDLE btw), it will not pick up the table it just created: from sqlalchemy import * db = create_engine('mssql://login:[EMAIL PROTECTED]/dbname') metadata = BoundMetaData(db) z_table_test = Table('z_table', metadata, autoload=True) Traceback (most recent call last): File pyshell#3, line 1, in -toplevel- z_table_test = Table('z_table', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: z_table Consequently when I do the above I cannot reflect any of the pre- existing tables in the database. When I check the database itself 'z_table' really does exist and I can query it in Query Analyzer and modify it in Enterprise Manager. Thanks again for your 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: mssql reflection NoSuchTableError
So all of the above was done with Windows XP, Python 2.4.3, pymssql 0.7.4, and MSSQL 2000. I upgraded to pymssql 0.8.0 with the same results. I uninstalled that and installed pyodbc 2.0.3.6, same results. The obvious differences between my installation and yours is that I am using MSSQL 2000 and Python 2.4.3. Not exactly sure what else to do here other than experiment with the 'schema' and 'owner' arguments on Table(). Any other suggestions? Thanks again --~--~-~--~~~---~--~~ 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: Problems with non existing relations
un 12, 3:59 pm, voltron [EMAIL PROTECTED] wrote: actually, I am iterating through all the databases in the meta ti = model.meta.table_iterator() for t in ti: print create %s ? % t if raw_input(Choose [Y/n]).lower() in ['y','']: t.create() I want to be able to chose which database to create from a pool on database models well then youre going to want to say Y on users if you plan to say Y on user_roles. --~--~-~--~~~---~--~~ 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: mssql reflection NoSuchTableError
On Jun 12, 9:04 pm, one.person [EMAIL PROTECTED] wrote: So all of the above was done with Windows XP, Python 2.4.3, pymssql 0.7.4, and MSSQL 2000. I upgraded to pymssql 0.8.0 with the same results. I uninstalled that and installed pyodbc 2.0.3.6, same results. The obvious differences between my installation and yours is that I am using MSSQL 2000 and Python 2.4.3. Not exactly sure what else to do here other than experiment with the 'schema' and 'owner' arguments on Table(). Any other suggestions? turn on query logging and see whats wrong with the queries themselves, when it goes to load data about the tables. try them manually, etc. --~--~-~--~~~---~--~~ 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: mssql reflection NoSuchTableError
Thanks for all the quick replies. Currently on pyodbc 2.0.3.6. Anyway, I tried this (the table 'zones' most definitely exists): metadata.engine.echo = True zones_table = Table('zones', metadata, autoload=True) 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 SET nocount ON 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 None 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 SELECT [COLUMNS_eba4].[TABLE_SCHEMA], [COLUMNS_eba4].[TABLE_NAME], [COLUMNS_eba4].[COLUMN_NAME], [COLUMNS_eba4].[IS_NULLABLE], [COLUMNS_eba4].[DATA_TYPE], [COLUMNS_eba4].[ORDINAL_POSITION], [COLUMNS_eba4].[CHARACTER_MAXIMUM_LENGTH], [COLUMNS_eba4]. [NUMERIC_PRECISION], [COLUMNS_eba4].[NUMERIC_SCALE], [COLUMNS_eba4]. [COLUMN_DEFAULT] FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_eba4] WHERE [COLUMNS_eba4].[TABLE_NAME] = ? AND [COLUMNS_eba4]. [TABLE_SCHEMA] = ? ORDER BY [COLUMNS_eba4].[ORDINAL_POSITION] 2007-06-12 18:20:40,940 INFO sqlalchemy.engine.base.Engine.0x..b0 ['zones', 'dbo'] Traceback (most recent call last): File pyshell#6, line 1, in -toplevel- zones_table = Table('zones', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: zones I think that was what you guys meant by query logging --~--~-~--~~~---~--~~ 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: mssql reflection NoSuchTableError
That looks OK to me. Try pasting that query (cleaned-up) into a query window on Enterprise Manager and see what kind of results you get. The ? arguments are positional, so the first would be the table 'zone'; the second the schema 'dbo'. On 6/12/07, one.person [EMAIL PROTECTED] wrote: Thanks for all the quick replies. Currently on pyodbc 2.0.3.6. Anyway, I tried this (the table 'zones' most definitely exists): metadata.engine.echo = True zones_table = Table('zones', metadata, autoload=True) 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 SET nocount ON 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 None 2007-06-12 18:20:40,924 INFO sqlalchemy.engine.base.Engine.0x..b0 SELECT [COLUMNS_eba4].[TABLE_SCHEMA], [COLUMNS_eba4].[TABLE_NAME], [COLUMNS_eba4].[COLUMN_NAME], [COLUMNS_eba4].[IS_NULLABLE], [COLUMNS_eba4].[DATA_TYPE], [COLUMNS_eba4].[ORDINAL_POSITION], [COLUMNS_eba4].[CHARACTER_MAXIMUM_LENGTH], [COLUMNS_eba4]. [NUMERIC_PRECISION], [COLUMNS_eba4].[NUMERIC_SCALE], [COLUMNS_eba4]. [COLUMN_DEFAULT] FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_eba4] WHERE [COLUMNS_eba4].[TABLE_NAME] = ? AND [COLUMNS_eba4]. [TABLE_SCHEMA] = ? ORDER BY [COLUMNS_eba4].[ORDINAL_POSITION] 2007-06-12 18:20:40,940 INFO sqlalchemy.engine.base.Engine.0x..b0 ['zones', 'dbo'] Traceback (most recent call last): File pyshell#6, line 1, in -toplevel- zones_table = Table('zones', metadata, autoload=True) File build\bdist.win32\egg\sqlalchemy\schema.py, line 166, in __call__ File build\bdist.win32\egg\sqlalchemy\engine\base.py, line 809, in reflecttable File build\bdist.win32\egg\sqlalchemy\databases\mssql.py, line 506, in reflecttable NoSuchTableError: zones I think that was what you guys meant by query logging --~--~-~--~~~---~--~~ 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] Erroneous primary key of in-memory instance after session flush?
I was converting an older table definition from using an integer primary key to a string (representation of UUID), and ran into a bit of strange behavior, where my object instance's String primary key receives an integer value (which appears to be the internal sqlite rowid) after a flush. From prior reading, I believed that I ought to be able to use a non-integer primary key. I was using 0.3.8 when I first run into this, but it appears to hold true for the current SVN trunk as well. It may just be with the sqlite layer (the DB I've been using and the only one I have handy), or it may be an issue with handling default values for primary key columns, I'm not sure. For a short sample exhibiting the problem: - - - - - - - - - - - - - - - - - - - - - - - - - import uuid from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite:///') meta = BoundMetaData(engine) def default_uuid(): return str(uuid.uuid4()) test_table = Table( 'test', meta, Column('uuid', String, default=default_uuid, primary_key=True), ) class Test(object): pass test_mapper = mapper(Test, test_table) if __name__ == __main__: meta.create_all() s = create_session(engine) test = Test() # Works if the line below is uncommented # test.uuid = default_uuid() s.save(test) s.flush() print 'Post-Flush:', test.uuid u = test_table.select().execute().fetchone() print 'DB:', u - - - - - - - - - - - - - - - - - - - - - - - - - When run as is above, the output for me looks like: Post-Flush: 1 DB: (u'1cfcb156-2a90-42ec-9c96-75a4b8bf60e7',) (If you enable tracing on the engine, you can see that the actual uuid column value inserted into the database during the flush is, in fact, the data shown from the select, which doesn't match that in the object instance in memory following the flush) Running with the commented line (manual key assignment) uncommented, yields: Post-Flush: d05ebdde-267f-43ae-a7df-f6d588e431a2 DB: (u'd05ebdde-267f-43ae-a7df-f6d588e431a2',) which is what I originally expected for the first case. Now, I know that sqlite is internally creating a rowid field since I don't have an Integer primary key, and I'm presuming that's what the erroneous 1 value is in the first case (it is, in fact, an 'int', not a string), but I don't know why it's being assigned to my in-memory copy of the object, and since that's the primary key field, it no longer maps properly to the database. Am I doing something wrong in the above? Thanks. -- David --~--~-~--~~~---~--~~ 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] Trying to detect which class methods were added by the mapper.
Inspired by the SQLAlchemy docs, I'm writing a documentation generator in python using a combination of epydoc (for parsing/introspection), genshi (templates), docutils (for restructured text), and pygments (syntax highlighting).. and I just noticed that the documentation for classes mapped by SQLAlchemy always includes the methods like select, count, get_by, etc that were added by the mapper. This is very undesirable, and I'm looking for a way to detect which methods were added to the class by the SQLAlchemy mapper, and which methods were there to begin with. Does anyone have any ideas? I was hoping there would be something like Animal.select.mapper or Animal.select._sqlalchemy that I could use to differentiate which methods were added by the mapper and which were there originally, but I can't seem to find any such thing. many thanks in advance, -Ian Charnas from the Pagoda CMS team, www.pagodacms.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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---