Re: [sqlalchemy] expected error with scalar() but got None instead

2010-09-23 Thread Chris Withers
On 23/09/2010 15:29, Michael Bayer wrote: repr(engine.execute(select([sequences.c.current], sequences.c.name=='foo')).scalar()) 'None' Why do I get None instead of an exception raised? 'None' is a scalaryou're thinking of 'query.one()' perhaps. ...but it has no meaning. My understandin

Re: [sqlalchemy] SQLAlchemy / Turbogears2.0 transaction rollbacks

2010-09-24 Thread Chris Withers
On 09/09/2010 20:51, ozwyzard wrote: TG2 uses scoped sessions and uses an additional layer of transaction manager. If I have a scenario as follows: import transaction def main() try: add main_record to session query main_record to get primary key call foo()

[sqlalchemy] example out of date?

2010-09-24 Thread Chris Withers
Hi All, http://www.sqlalchemy.org/docs/orm/examples.html?highlight=mapperextension#xml-persistence ...makes reference to a MapperExtension in optimized_al.py, however I can find no mapper extension in that file. Was it ever there or am I just missing something? cheers, Chris -- You receive

Re: [sqlalchemy] Batch Delete with ORM

2010-10-05 Thread Chris Withers
On 04/10/2010 13:16, Mark Erbaugh wrote: If I were doing this in SQL, I would to the first command as SELECT count(*) FROM period WHERE period.cycle = ? Why would you do this first? Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To pos

Re: [sqlalchemy] MySQL DATE_ADD function

2010-10-05 Thread Chris Withers
On 04/10/2010 22:53, Bryan wrote: I'm having trouble converting this SQL into an ORM statement. DATE_ADD(datecol, INTERVAL(1 - DAYOFWEEK(datecol)) DAY) This is as far as I can get, which is basically nowhere. The second argument to date_add requires literal strings "INTERVAL" and "DAY", but I

[sqlalchemy] bug with declarative's _decl_class_registry

2010-10-05 Thread Chris Withers
Hi All, Start off with a base.py module: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() Now, say we have a module, a.py: from sqlalchemy import * from base import Base class Something(Base): __tablename__ = 'foo' id = Column('id', Integer, primary_ke

Re: [sqlalchemy] bug with declarative's _decl_class_registry

2010-10-05 Thread Chris Withers
On 05/10/2010 16:10, Michael Bayer wrote: I think an exception should be raised if a class name already exists in _decl_class_registry when the assignment is made in _as_declarative. yeah definitely, though in 0.6 it needs to be a warning to start since some folks might be doing this semi-int

Re: [sqlalchemy] Session problems

2010-10-06 Thread Chris Withers
On 06/10/2010 10:46, Warwick Prince wrote: (InterfaceError) 2055: Lost connection to MySQL server at '192.168.50.2:3306 ', system error: 10054 u'SELECT products.. ...it would be interesting to see the rest of that error message... Chris -- You received this messa

Re: [sqlalchemy] bug with declarative's _decl_class_registry

2010-10-06 Thread Chris Withers
On 05/10/2010 18:03, Michael Bayer wrote: Also, is there a 'trunk' or 'tip' anywhere now to put 0.7-targeted code? there's not. You'd make a bitbucket repo and link to it on the trac ticket. Done: http://www.sqlalchemy.org/trac/changeset/6868:d8580d6765d4 http://www.sqlalchemy.org/trac/t

[sqlalchemy] missing bind parameters don't raise exceptions

2010-10-07 Thread Chris Withers
Hi, I'd expect this: session.execute( 'select * from foo where bar=:baz', {} ) ...to raise an exception. It doesn't, why not? Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegr

Re: [sqlalchemy] missing bind parameters don't raise exceptions

2010-10-07 Thread Chris Withers
On 07/10/2010 16:01, Michael Bayer wrote: It doesn't, why not? Session.execute() creates text(), and text() creates a bindparam() object for :baz which has a value of None by default. Do it like this if you like: session.execute( text("select * from foo where bar=:baz", bindparams=[bindpar

Re: [sqlalchemy] Fwd: [Gnukhata-devel] Error installing gnukhata

2010-10-13 Thread Chris Withers
On 13/10/2010 08:29, Krishnakant Mane wrote: Don't know why this might be happening on an Ubuntu 10.04 machine? Can some one help solve this? How were any of the involved packages installed? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www

[sqlalchemy] getting floats instead of decimals from session.execute

2010-10-13 Thread Chris Withers
Hi All, If I'm doing: session.execute('select some_numeric from some_table') ...how do I get floats back in the result instead of decimals? Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@g

Re: [sqlalchemy] getting floats instead of decimals from session.execute

2010-10-13 Thread Chris Withers
On 13/10/2010 22:37, Michael Bayer wrote: use text() with Numeric(as_decimal=False) I can't quite join the dots on this one... I get passed a bunch of sql to execute, I don't have control over that. Where do I wire in Numeric(as_decimal=False) and how do I tell where I need to given an arbitr

Re: [sqlalchemy] getting floats instead of decimals from session.execute

2010-10-14 Thread Chris Withers
On 14/10/2010 17:10, Michael Bayer wrote: I get passed a bunch of sql to execute, I don't have control over that. Where do I wire in Numeric(as_decimal=False) and how do I tell where I need to given an arbitrary select as a string of sql? text() is in the docs, including an example of typema

[sqlalchemy] efficiently setting many to many collections when I have a sequence of ids.

2010-10-14 Thread Chris Withers
Hi All, I currently have code that looks like this: recipients = [] if recipient_ids: for id in recipient_ids.split(','): recipients.append( session.query(recipient.Recipient).filter_by(id=id).one() ) else: recipient_ids = () feed.recipients = recipients Where the m

[sqlalchemy] sqlite databases leaking between unit tests

2010-10-19 Thread Chris Withers
On 18/10/2010 17:57, Michael Bayer wrote: issue #2, I've tried to emphasize this as much as possible in the documentation, the SQLite dialect uses *one connection* for the thread, by default. This default is being changed in 0.7 (so in 0.7, the common issue will become "database is locked" i

Re: [sqlalchemy] sqlite databases leaking between unit tests

2010-10-19 Thread Chris Withers
On 19/10/2010 17:14, Michael Bayer wrote: The problem I have is that despite the fact that I create the engine for every test, I'm still seeing tables and row entries surviving across tests, but only when one or more tests fail. its not possible at all if you're using a :memory: database an

[sqlalchemy] reflecting database names and table types?

2010-10-22 Thread Chris Withers
Hi Guys, Is there any way I can reflect the names of databases in a MySQL server and a list of the tables in each database, along with whether or not each database is MyISAM or InnoDB? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http:

[sqlalchemy] 'MySQL server has gone away' problem

2010-10-23 Thread Chris Withers
Hi Guys, One of our MySQL servers crashed yesterday. After we recovered it, a small SQLAlchemy-based app we have running against it kept throwing 'MySQL server has gone away' even though we have pool_recycle set to 3600. Any ideas why that might be? Curious as to why SA doesn't try and reconn

Re: [sqlalchemy] Subtransactions

2010-11-01 Thread Chris Withers
On 01/11/2010 15:19, Michael Bayer wrote: "nested" = uses SAVEPOINT. This is the technique the average user wants to use. Background: http://en.wikipedia.org/wiki/Savepoint How do you roll back to a savepoint in SA? Chris -- Simplistix - Content Management, Batch Processing & Python Consultin

Re: [sqlalchemy] Secialists question: how to do implement stock-management

2010-11-25 Thread Chris Withers
On 30/10/2010 02:43, Warwick Prince wrote: We can continue this one-on-one outside the group. Send your questions to me. I prefer Skype for this type of thing - see my Skype id below. ...except the rest of the group doesn't then benefit fgrom the discussion ;-) The discussion is only sli

Re: [sqlalchemy] Convert Declarative definitions to Table definitions

2010-12-06 Thread Chris Withers
On 03/12/2010 19:02, Thadeus Burgess wrote: I'm about to use sqlalchemy-migrate, however all of my tables are already in a declarative format. If you're using migrate, you're better off reflecting the tables to be migrated rather than using any script to try and turn declarative models into t

Re: [sqlalchemy] SQLAlchemy 0.6.6 Released

2011-01-10 Thread Chris Withers
On 09/01/2011 16:25, Michael Bayer wrote: The limitations of distutils are also troubling here. In my own work app, we use pip in conjunction with a Makefile and for the SQLAlchemy install the flag is on in the Makefile. In that regard the flag being off by default doesn't feel like that b

Re: [sqlalchemy] unittest assertRaises does not catch NoResultFound

2011-01-14 Thread Chris Withers
On 11/01/2011 15:26, Michael Bayer wrote: On Jan 11, 2011, at 4:56 AM, pr64 wrote: self.assertEqual(self.session.query(User).filter(User.firstname == "user1_fn").count(), 1) self.assertRaises(NoResultFound, self.session.query(User).filter(User.firstname == "other_fn").one()) asser

Re: [sqlalchemy] Re: guard all session.query with try except?

2011-01-14 Thread Chris Withers
On 14/01/2011 06:59, can xiang wrote: Thanks for your advise. My application is a tornadoweb app. So I'm going to create Session() for each request. Tornado is an async framework, right? If so, you may be in for a bumpy ride unless you get all SQLAlchemy stuff happening in threads... cheer

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Chris Withers
Hi Martin, On 08/02/2011 19:25, Martijn Moeling wrote: I am not sure I get your point. How do I set up a common "Base". I could do Base= Declarative_base() from a import A (or * not sure how this differs in this case) from b import B (or *) If I do not declare Base in module "a" I get an Imp

[sqlalchemy] altering metadata when performing column changes

2011-02-10 Thread Chris Withers
Hi Domen, Am I right in remembering that last year you said the alter_metadata=False was an experimental feature which turned out not to be useful and so could be removed? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplist

Re: [sqlalchemy] altering metadata when performing column changes

2011-02-10 Thread Chris Withers
Sorry, this was meant for the sqlalchemy-migrate group... Chris On 10/02/2011 13:19, Chris Withers wrote: Hi Domen, Am I right in remembering that last year you said the alter_metadata=False was an experimental feature which turned out not to be useful and so could be removed? cheers, Chris

Re: [sqlalchemy] Pypi release policy

2011-02-16 Thread Chris Withers
On 15/02/2011 14:27, Eric Lemoine wrote: But aren't apps supposed to use<=0.6.99 to avoid backward compats issues? Well, I wish I could just say < 0.7 but I guess that would suck in 0.7 betas? Tarek? That said, this is spot on. Honestly, it's up to the consuming package/project to limit wha

[sqlalchemy] mortar_rdb 1.0.0 released!

2011-02-18 Thread Chris Withers
Hi All, I'm very pleased to finally announce the release of mortar_rdb 1.0.0. This package ties together SQLAlchemy, sqlalchemy-migrate and the component architecture to make it easy to develop projects using SQLAlchemy through their complete lifecycle. While I'll be using it with Pyramid, the

Re: [sqlalchemy] Need Urgent Help -Many to Many Relations

2011-02-18 Thread Chris Withers
On 17/02/2011 11:07, Abdul Gaffar wrote: Hi all, Can I respectfully suggest that you read the following carefully: http://www.catb.org/~esr/faqs/smart-questions.html Specifically: http://www.catb.org/~esr/faqs/smart-questions.html#urgent Repeat postings of the same question are pretty annoy

[sqlalchemy] cascading deletes

2011-02-25 Thread Chris Withers
Hi All, I have the following models: class IP(Base): __tablename__ = 'ip' username = Column(String(50), ForeignKey('user.username'), primary_key=True) ip = Column(String(15), primary_key=True, index=True) class User(Base): __tablename_

[sqlalchemy] auto-flush not flushing, cascade misbehaving

2011-02-25 Thread Chris Withers
Hi All, With these models: class User(Base): __tablename__ = 'user' __table_args__ = {'mysql_engine':'InnoDB'} username = Column(String(50), primary_key=True) grants = dynamic_loader("Grant") class Grant(Base): __tablename__ = 'grant' __table_args__ = {'mysql_engine':'I

Re: [sqlalchemy] auto-flush getting order of inserts wrong when sessionmaker used

2011-02-26 Thread Chris Withers
On 25/02/2011 17:13, Michael Bayer wrote: can't reproduce. See attached.This test includes randomization of all key data structures in the UOW which smokes out any issues in dependency sorting. Okay, so after about an hour of stripping down code, please find attached a minimal reproducib

Re: [sqlalchemy] Re: Exception catching, rollback clarification

2011-02-26 Thread Chris Withers
On 26/02/2011 09:09, Romy wrote: It sounds like a better approach would be to wrap each request handler's code as follows: try: RequestHandler() elixir.session.commit() except: elixir.session.rollback() raise finally: elixir.session.remove() Q1: Is this, in fact, the better appro

Re: [sqlalchemy] auto-flush getting order of inserts wrong when sessionmaker used

2011-02-26 Thread Chris Withers
On 26/02/2011 15:50, Michael Bayer wrote: On 25/02/2011 17:13, Michael Bayer wrote: can't reproduce. See attached.This test includes randomization of all key data structures in the UOW which smokes out any issues in dependency sorting. Okay, so after about an hour of stripping down cod

Re: [sqlalchemy] auto-flush getting order of inserts wrong when sessionmaker used

2011-02-27 Thread Chris Withers
On 27/02/2011 06:34, Michael Bayer wrote: More interestingly, why does the use of sessionmaker versus the use of the standard Session class make a difference? the unit of work issues INSERTS in order for a single kind of entity.It doesn't do that across all entities since the dependency

[sqlalchemy] iterate_to_root

2011-02-27 Thread Chris Withers
Hi All, I'm reading http://www.sqlalchemy.org/trac/browser/examples/versioning/history_meta.py?rev=7253:3ef75b251d06 and I'm curious about the following in line 112-114: - what does iterate_to_root do? - why do we need to iterate over the object mappers and the history mappers? - what does

[sqlalchemy] SessionExtension and cascading

2011-02-27 Thread Chris Withers
Hi All, In the before_flush of a SessionExtension, is there any way I can tell if an object is in session.deleted as a result of being deleted in its own right or as a result of being cascaded from the delete of another object? cheers, Chris -- Simplistix - Content Management, Batch Proces

[sqlalchemy] mortar_rdb 1.1.0 released!

2011-02-27 Thread Chris Withers
Hi All, I'm pleased to announce a new release of mortar_rdb. This package ties together SQLAlchemy, sqlalchemy-migrate and the component architecture to make it easy to develop projects using SQLAlchemy through their complete lifecycle. This release allows you to register SessionExtensions with

Re: [sqlalchemy] SessionExtension and cascading

2011-02-27 Thread Chris Withers
On 27/02/2011 23:20, Michael Bayer wrote: hmm ! not really actually. No probs, I thought that'd be a bit of a stretch ;-) Also, some deletes, such as for de-associated orphans, don't get added to "delete" until after before_flush(). Hmm, does this imply that the versioning recipes that

Re: [sqlalchemy] trouble with metaclass

2011-03-17 Thread Chris Withers
On 16/03/2011 21:01, farcat wrote: I have an error i cant figure out (likely a beginners error): Beginners should not be using metaclasses. What's your use case here? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- Y

Re: [sqlalchemy] Re: trouble with metaclass

2011-03-20 Thread Chris Withers
On 19/03/2011 10:27, farcat wrote: OK, dumb error, move Base.metadata.create_all(engine) below table1 = tablemeta("table1") and it works. This works when I create the columns via the temp dict in __new__ not when I do so in __init__ (it complains about missing __tabledata__), but why? I'd st

Re: [sqlalchemy] Re: trouble with metaclass

2011-03-21 Thread Chris Withers
On 21/03/2011 19:29, farcat wrote: Hi Chris, The short answer is that I want to dynamically create classes/tables Why? and I want to implement multiple inheritance That's fine, that's what mixins give you. If you have more than one class with a __tablename__ in the class hierarchy, then y

Re: [sqlalchemy] InvalidRequestError

2011-03-31 Thread Chris Withers
On 12/03/2011 00:51, AJAY PATTNI wrote: We use a global session as follows: __session__ = scoped_session(sessionmaker(twophase=False,transactional=True,autoflush=True,extension=ZopeTransactionExtension())) All the rest of the transactional machinery is handled by Elixiry Entity object. So my q

Re: [sqlalchemy] Re: trouble with metaclass

2011-04-04 Thread Chris Withers
On 23/03/2011 09:14, lars van gemerden wrote: - I want to generate classes/tables based on metadata in another table in the database, filled by "designers" not programmers. Then you should be creating Tables and Mappers, not attempting to use Declarative. - Multiple inheritance

[sqlalchemy] unicode "everywhere"

2011-04-12 Thread Chris Withers
Hi All, I'm keen to avoid being bitten by annoying unicode decoding and encoding errors, particularly later during project development (you know, when the stuff that no longer fits into the encoding you accidentally used turns up once you think development is done and dusted ;-) ) What's the

Re: [sqlalchemy] Do you have a way to track easily the source of « SAWarning: Unicode type received non-unicode bind param value. » ?

2011-05-23 Thread Chris Withers
On 23/05/2011 08:47, Stéphane Klein wrote: I know I have a bad assignation, I've put a string in unicode field but I don't found where. What tip do you use to found it ? I think you can do this by setting the warning filter to error early in your application: import warnings warnings.filter

[sqlalchemy] accessing MS SQL Server from Linux

2011-05-29 Thread Chris Withers
Hi All, Is it possible, and if it is, what's the best way, to access a Microsoft SQL Server instance from a Linux (RHEL, as it happens) box using SQLAlchemy? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- Yo

[sqlalchemy] mapping stored procedures results to an object

2011-06-07 Thread Chris Withers
Hi All, Are there any example knocking about of mapping the results of a MySQL stored procedure to an object? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscrib

[sqlalchemy] db name from session?

2011-06-15 Thread Chris Withers
Hi All, If I have a session object, what's the correct way to get the name of the db that session is attached to? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subs

Re: [sqlalchemy] db name from session?

2011-06-15 Thread Chris Withers
On 15/06/2011 10:48, Chris Withers wrote: Hi All, If I have a session object, what's the correct way to get the name of the db that session is attached to? session.bind.url.database ...looks like what I want. Is it legit to use that? cheers, Chris -- Simplistix - Content Management,

[sqlalchemy] doing silly things, expected exception

2011-06-15 Thread Chris Withers
Hi All, I tried to execute a lump of sql with: session.execute(sql) The lump contains multiple statements, comments and ddl. Which of those should I have not been doing? (and what is the best way to execute a lump of sql statements?) Anyway, the outcome was no error but nothing happening eithe

Re: [sqlalchemy] doing silly things, expected exception

2011-06-15 Thread Chris Withers
On 15/06/2011 14:39, Michael Bayer wrote: Okay, that makes sense, but why only a warning which is practically invisible rather than an exception? That's the _CursorFairy, which was making some old assumptions that if the cursor close is failing, we're probably already inside of an exception t

[sqlalchemy] reflective stored procedure names

2011-06-15 Thread Chris Withers
Hi All, Any plans to reflect the available stored procedures in SQLAlchemy, specifically with MySQL? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the

[sqlalchemy] call mysql procedure (as opposed to function) using sql expression language

2011-06-15 Thread Chris Withers
Hi All, So, if I have a MySQL function, I can call it as follows: result = session.execute(func.myfunc()).scalar() However, if that is instead a procedure, I get: OperationalError: (OperationalError) (1305, 'FUNCTION myfunc does not exist') 'SELECT myfunc() AS myfunc_1') I *do* get the corr

[sqlalchemy] fiddley mapping problem

2011-06-20 Thread Chris Withers
Hi All, I have the following table: CREATE TABLE `ip` ( `email` varchar(50) NOT NULL, `ip` varchar(15) NOT NULL, PRIMARY KEY (`email`,`ip`), ) ...which I'm looking to map to the following class: class User: def __init__(self,email,*ips): self.email=email self.ips = ips So,

Re: [sqlalchemy] fiddley mapping problem

2011-06-20 Thread Chris Withers
On 20/06/2011 17:27, Michael Bayer wrote: So, multiple rows in the `ip` table end up mapping to a single user objects. (ie: I end up with a sequence of ip addresses on user object) How do I do it? I would likely just map traditionally and have "User" be a non-mapped proxy object to a collect

Re: [sqlalchemy] call mysql procedure (as opposed to function) using sql expression language

2011-06-24 Thread Chris Withers
On 15/06/2011 19:13, Michael Bayer wrote: session.execute('call myfunc()').scalar() ...but is there a way I can generate that? i havent worked with MySQL sps but maybe there's a way to CREATE FUNCTION instead of SP, not sure, otherwise you'd probably want to do this: class Call(ClauseElement

[sqlalchemy] mortar_rdb 1.2.0 released!

2011-06-30 Thread Chris Withers
Hi All, I'm pleased to announce a new release of mortar_rdb. This package ties together SQLAlchemy, sqlalchemy-migrate and the component architecture to make it easy to develop projects using SQLAlchemy through their complete lifecycle. Changes in this release were: - Pass None as the default

Re: [sqlalchemy] mortar_rdb 1.2.0 released!

2011-07-17 Thread Chris Withers
On 30/06/2011 09:30, Wichert Akkerman wrote: On 06/30/2011 10:14 AM, Chris Withers wrote: - Specify sqlalchemy 0.6 as a requirement, until zope.sqlalchemy is ported, mortar_rdb shouldn't be used with :mod:`sqlalchemy` 0.7. What is missing? zope.sqlalchemy seems to work fine with sqlal

Re: [sqlalchemy] mortar_rdb 1.2.0 released!

2011-07-17 Thread Chris Withers
On 17/07/2011 10:12, Wichert Akkerman wrote: On 2011-7-17 11:07, Chris Withers wrote: On 30/06/2011 09:30, Wichert Akkerman wrote: On 06/30/2011 10:14 AM, Chris Withers wrote: - Specify sqlalchemy 0.6 as a requirement, until zope.sqlalchemy is ported, mortar_rdb shouldn't be used with

[sqlalchemy] misleading docs on logging

2011-08-02 Thread Chris Withers
Hi All, Just me or does this: http://www.sqlalchemy.org/docs/core/engines.html?highlight=logging#configuring-logging ...imply that to get pool logging you just need to do: import logging logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG) Whereas, in fact, you need to do: import log

Re: [sqlalchemy] misleading docs on logging

2011-08-05 Thread Chris Withers
On 03/08/2011 01:01, Michael Bayer wrote: import logging logging.getLogger('sqlalchemy').setLevel(logging.INFO) logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG) logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING) logging.getLogger('sqlalchemy.mapper').setLevel(logging.WAR

[sqlalchemy] delcarative with autoload when you have no connection

2011-09-27 Thread Chris Withers
Hi All, Say I have a class such as: class MyObj(Base) __tablename__='mytable' __table_args__=dict(autoload=True) ...but the Base's metadata isn't bound, and won't be until the app has started (ie: the model has been imported) as the connection string comes from the environment. Is

[sqlalchemy] what pool to use when using pgbouncer?

2011-09-27 Thread Chris Withers
Hi, I'm wondering what the recommended incantation of create_engine is in SA 0.7.3 if: - you're using pg_bouncer, and so essentially don't want a pool - you have a DSN, eg: 'host=xx dname=xx user=xx password=xx', rather than a SA url cheers, Chris -- Simplistix - Content Management, Batch

Re: [sqlalchemy] delcarative with autoload when you have no connection

2011-09-27 Thread Chris Withers
On 27/09/2011 16:58, Michael Bayer wrote: ah, hm. interesting ! basically, not rea..^H^H^H OK actually this is very easy, using a technique I used previously to create abstract concrete mappers. This should probably be how we recommend people use reflection with mappings since this is

Re: [sqlalchemy] delcarative with autoload when you have no connection

2011-09-27 Thread Chris Withers
On 27/09/2011 18:10, Michael Bayer wrote: That looks like it should ship with SA itself... Does it? on the website, sure :) Many of these things are better as recipes Meh, that used to be true of mixins. I'm very glad that's now in the core. The trouble with keeping this as a recipe is t

[sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
Hi, Much less controversial question this time, I hope ;-) I have: class MyModel(Base) ... I want to do: engine = create_engine(...) engine.execute(DropTable(MyModel.__table__)) engine.execute(CreateTable(MyModel.__table__)) ...of course, this barfs the first time I run it as the table d

Re: [sqlalchemy] delcarative with autoload when you have no connection

2011-09-28 Thread Chris Withers
On 27/09/2011 18:48, Michael Bayer wrote: (Note to readers: Chris and I hang out each year at Pycon. He's a great guy, so forgive the colloquial tone I take with him !) Likewise, I should point out I have huge amounts of respect for Mike, so if I'm grumbling, it's usually 'cos he's right ;-

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
On 28/09/2011 13:19, Michael Bayer wrote: well the easiest is mytable.drop(engine, checkfirst=True). The "check" is not within the DropTable construct, which represents just the actual DROP TABLE statement.If you were using DropTable directly you'd call engine.has_table(tablename) first to

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
On 28/09/2011 14:09, Michael Bayer wrote: Hmm, but both mysql and postgres (I suspect others do too, but I haven't checked) have "DROP TABLE IF EXISTS" statements so you don't need to do any checking. That feels like it should be supported by the DropTable construct, what am I missing? oh, th

Re: [sqlalchemy] what pool to use when using pgbouncer?

2011-10-01 Thread Chris Withers
On 27/09/2011 18:24, Michael Bayer wrote: On Sep 27, 2011, at 10:55 AM, Chris Withers wrote: Hi, I'm wondering what the recommended incantation of create_engine is in SA 0.7.3 if: - you're using pg_bouncer, and so essentially don't want a pool for that you use NullPool

[sqlalchemy] packages, modules and double imports - oh my!

2011-10-03 Thread Chris Withers
Hi All, The attached package gives that smallest possible example of problems I'm hitting with some SQLAlchemy declarative classes. In short, I want to be able to do: python -m pack.module and have if the __name__=='__main__' block spit out the SQL to create the tables necessary for the modu

Re: [sqlalchemy] packages, modules and double imports - oh my!

2011-10-03 Thread Chris Withers
On 03/10/2011 15:15, Michael Bayer wrote: ive no idea what __main__.py is either ? where's the SQLAlchemy exceptions here ? (keeping in mind i havent yet gone through all the steps to download a file...untar it...figure out what you're trying to do...) The attached .tgz simplifies the real

[sqlalchemy] query returns a non-result?

2011-11-03 Thread Chris Withers
Hi All, Any idea what this traceback is about? This query normally works fine and is run a few hundred times a day ;-) cheers, Chris Original Message session.query(PasswordRequest).with_lockmode('update').all(): File "SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py", lin

Re: [sqlalchemy] query returns a non-result?

2011-11-11 Thread Chris Withers
On 04/11/2011 19:04, Michael Bayer wrote: Anyway, SQLAlchemy raises the error you see if you call fetchone()/all() on a result set where cursor.description is not present. Why query(X).with_lockmode('update').all() is doing this appears to be some bug in your DBAPI, because all() emits a SELE

[sqlalchemy] reflected declarative versus single table inheritance

2012-02-09 Thread Chris Withers
Hi, I'm hitting some issues with single table inheritance and the reflected declarative example interacting badly... I'm not sure I have my head around this 100% and certainly no idea what to do about it, so thought I'd see what others (Mike ;-) ) think... IIUC, the following breaks: class

[sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
Hi Again, I'm wondering if the use case I have is one that is supported... So, the situation is that I have a bunch of classes that I need to map to a bunch of tables, and I'd prefer to do that declaratively. The spicey bit is that I need to connect to several environments a lot of the time a

Re: [sqlalchemy] reflected declarative versus single table inheritance

2012-02-09 Thread Chris Withers
On 09/02/2012 15:47, Chris Withers wrote: My thinking was leaning towards actually abandoning the full declarative base and coming up with a light weight one (or maybe even class decorator) that basically added recorded the class in a sequence (much like the declarative reflection does) and then

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
On 09/02/2012 19:51, Michael Bayer wrote: So, my plan is to have one engine per database I connect to. But what to do about tables? So what does it mean for your application to import a module, that has a class "MyClass", which should be mapped to a table, but when the app is running, that t

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
On 09/02/2012 20:06, Michael Bayer wrote: On Feb 9, 2012, at 3:02 PM, Chris Withers wrote: Almost, but... We can't have per-connection models, that would be semantically weird. Using a different metadata at session creation time, keyed off the dsn of the database connected to, and

Re: [sqlalchemy] reflected declarative versus single table inheritance

2012-02-10 Thread Chris Withers
On 09/02/2012 19:47, Michael Bayer wrote: OK I'm not sure if you are on 0.7.5 Yep, this project is. but the string name of the column is accepted for "polymorphic_on". Cool, any plans for primary key? The recipe just needs to fill in the 'inherits' keyword within prepare(), and that's i

[sqlalchemy] reflected tables don't reflect foreign key relationships?

2012-02-16 Thread Chris Withers
Hi All, Is it true that reflected tables don't reflect foreign key relationships? I'm having to specify the columns with foreign keys manually using the declarative reflected pattern and wondering why... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting

Re: [sqlalchemy] reflected tables don't reflect foreign key relationships?

2012-02-16 Thread Chris Withers
On 16/02/2012 14:38, Michael Bayer wrote: We reflect foreign keys with a vengeance, with the light from like two dozen unit tests forged from sweat and tears... Okay, postgres on this one... Using the reflected declarative pattern. Unless I manually specify the column with the foreign key in

[sqlalchemy] alembic questions/comments

2012-02-21 Thread Chris Withers
Hi Mike, I've been reading the Alembic docs, and the following popped out: - The "partial guid" approach is nice for machines, but a nightmare for humans, looking at a folder full of these can't be fun. Since it's the link in the file that's important, could the files be given friendly names

[sqlalchemy] support for postgres inheritance in sqlalchemy

2012-02-23 Thread Chris Withers
Hi All, Where can I find good example of declaratively mapping model classes to postgres tables where inheritance is involved? (eg: create table foo_2012_02_23 inherits foo) Also, if I reflect a database containing tables in this sructure, what will be reflected? Will all parent and child

Re: [sqlalchemy] support for postgres inheritance in sqlalchemy

2012-02-23 Thread Chris Withers
On 23/02/2012 13:05, Michael Bayer wrote: We only have a recipe where we assume INHERITS is used like the PG docs say in http://www.postgresql.org/docs/9.0/static/ddl-partitioning.html#DDL-PARTITIONING-IMPLEMENTATION . That is, child tables don't have any extra columns. In this scenario, SQLA

Re: [sqlalchemy] alembic questions/comments

2012-02-23 Thread Chris Withers
On 21/02/2012 18:41, Michael Bayer wrote: The current release does this: http://alembic.readthedocs.org/en/latest/tutorial.html#the-migration-environment http:/alembic.readthedocs.org/en/latest/tutorial.html#editing-the-ini-file (see "file_template") *goes to learn hg again* I thought I was

[sqlalchemy] How can I tell SA that a mutable attribute has changed?

2012-02-24 Thread Chris Withers
Hi All, I have a JSON field that's value is usually a dictionary: class MyModel(Base): config = Column(JSONType(255)) (Does SA have a JSONType now? we're using a homebrew one, that may be where the problem lies...) So, if I do: obj = session.query(MyModel).one() obj.config['foo'] += 1 se

Bug in old-style mutable type? (was Re: [sqlalchemy] How can I tell SA that a mutable attribute has changed?)

2012-02-24 Thread Chris Withers
On 24/02/2012 10:49, Chris Withers wrote: (Does SA have a JSONType now? we're using a homebrew one, that may be where the problem lies...) For reference, I've included the code for this type at the end of this email, it uses MutableType, so the following should work: obj = ses

Re: [sqlalchemy] short drop_all question

2012-02-24 Thread Chris Withers
On 24/02/2012 12:40, lars van gemerden wrote: can it be possible that drop_all does not empty the database of there are circular references between tables? You want: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything ...which is available here too: http://packages.python.org/mor

Re: [sqlalchemy] Re: short drop_all question

2012-02-24 Thread Chris Withers
I'll try using a sqlite file and closing and deleting the file in tearDown. Cheers, Lars On Feb 24, 2:28 pm, lars van gemerden wrote: Thanks very much, Nothing is ever easy ... :-( why not .. :-) On Feb 24, 2:11 pm, Chris Withers wrote: On 24/02/2012 12:40, lars va

[sqlalchemy] [alembic] can I just create_table from a model

2012-02-24 Thread Chris Withers
Hi All, When using Alembic, is there a way to just say "create the table required for this model" (well, okay "this model.__table__" ;-) ) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message bec

Re: [sqlalchemy] Re: short drop_all question

2012-02-28 Thread Chris Withers
On 25/02/2012 11:07, lars van gemerden wrote: Actually, now I think about it, i had a couple of reasons: - easy to start with (no separeate installation is i remember correctly) ...but bear in mind that it's a very weak database in terms of functionality... - no decision required about whi

Re: [sqlalchemy] Re: short drop_all question

2012-02-29 Thread Chris Withers
On 28/02/2012 19:56, lars van gemerden wrote: I can see that being true in the general case, and at some point i will start working with a serious database, but at the moment i am working on a prototype (in which db persistance is maybe a quarter of the work), still have a long list of items to i

[sqlalchemy] postgres "with .. select" queries

2012-02-29 Thread Chris Withers
How would I do a "with x as (...) select ..." in sqlalchemy orm-ish? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To pos

[sqlalchemy] orm query that returns millions of rows

2012-03-02 Thread Chris Withers
Hi All, I need to do a query that, in its simplest form, would be: for row in session.query(Message.body).order_by(Message.session_num): ...do read-only stuff with row and then discard... However, as that query will return roughly 20-40 million rows per time, I'm guessing the above may not

[sqlalchemy] Weird MySQL locking issue

2012-03-04 Thread Chris Withers
Hi All, I have a projects using SQLAlchemy 0.6.1 on a Zope app server where I have a SQLAlchemy session that's basically used to call a set of about 3 MySQL stored procedures to do some auth checks for the app. Sadly these stored procs are not maintained by me, and while I suspect they're the

<    1   2   3   4   5   >