[sqlalchemy] senseless warning messages escape python logging

2014-07-02 Thread Hans-Peter Jansen
Dear SQLAchemistas, this is an issue, that my apps choke on from time to time, _related_ to SQLA. Although, logging is set up correctly, some operations spit out senseless warning messages like this: /usr/lib/python2.6/site-packages/sqlalchemy/engine/default.py:324: Warning: Data truncated

[sqlalchemy] how to query one-to-many relationships, in a complicated way?

2014-07-02 Thread Chung WONG
Hi list, For this problem I am even having trouble think of a proper subject for it. I try my best to express as clear as possible and sorry for any confusions. Say there are three classes with relationship defined as below: class User(Base): __tablename__ = 'users' id = Column(Integer,

Re: [sqlalchemy] senseless warning messages escape python logging

2014-07-02 Thread Mike Bayer
we use the warnings filter to turn warnings into exceptions, either from the Python command line or programatically: https://docs.python.org/2/library/warnings.html https://docs.python.org/2/using/cmdline.html#cmdoption-W On 7/2/14, 3:26 AM, Hans-Peter Jansen wrote: Dear SQLAchemistas,

Re: [sqlalchemy] failed to locate a name error when using model with relationship

2014-07-02 Thread trustedbox
Hi Michael, thank you for the answer. Both classes are in the same file so I don't see how it could be possible that one class is used while other is not imported. Could you help me with that ? Andrey вторник, 1 июля 2014 г., 21:05:11 UTC+3 пользователь Michael Bayer написал: On 7/1/14,

Re: [sqlalchemy] failed to locate a name error when using model with relationship

2014-07-02 Thread Mike Bayer
On 7/2/14, 10:21 AM, trusted...@gmail.com wrote: Hi Michael, thank you for the answer. Both classes are in the same file so I don't see how it could be possible that one class is used while other is not imported. Could you help me with that ? that would mean you're doing something that is

[sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Brian Findlay
Hi Mike (et al.), I'm searching for a way to achieve defaultdict-like functionality for association proxies, so that a function that refers to a collection (or key within that collection) before it exists can create the collection/key with a default value. In a previous post

Re: [sqlalchemy] Postgresql - Index on a json field

2014-07-02 Thread Phillip Aquilina
This worked as described. Thanks again. I have a followup question. It doesn't seem like there's an analog to table.create(checkfirst=True) for an Index. I found this issue https://bitbucket.org/zzzeek/sqlalchemy/issue/527/indexcreate-should-take-checkfirst that seems to mention having this

Re: [sqlalchemy] Postgresql - Index on a json field

2014-07-02 Thread Mike Bayer
On 7/2/14, 11:38 AM, Phillip Aquilina wrote: This worked as described. Thanks again. I have a followup question. It doesn't seem like there's an analog to table.create(checkfirst=True) for an Index. I found this issue

Re: [sqlalchemy] Postgresql - Index on a json field

2014-07-02 Thread Phillip Aquilina
Perfect thanks Mike. On Wednesday, July 2, 2014 10:17:17 AM UTC-7, Michael Bayer wrote: On 7/2/14, 11:38 AM, Phillip Aquilina wrote: This worked as described. Thanks again. I have a followup question. It doesn't seem like there's an analog to table.create(checkfirst=True) for an

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Mike Bayer
On 7/2/14, 11:15 AM, Brian Findlay wrote: I've since added an event listener to perform a calculation each time a UserCourse object is set: # Recalculate 'bar' after updating UserCourse @event.listens_for(UserCourse.grade, 'set') def foo(target, value, oldvalue, initiator): courses =

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Brian Findlay
Mike, thanks for the response. (1) foo updates a particular User attribute based on a calculation performed on the user.courses collection. I'm listening for the set event on UserCourse objects to trigger foo to update that User attribute, but that isn't working with new users because -- as

[sqlalchemy] (Semi-)automated way to adjust constraint names via Alembic?

2014-07-02 Thread Ken Lareau
So, in my ongoing quest to make my team's operations database far more sane than it currently is, I want to fix all the constraint naming in the database to match the naming convention setting I have added to my SQLAlchemy configuration for the database. I could of course go through each table

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Mike Bayer
On 7/2/14, 2:59 PM, Brian Findlay wrote: Mike, thanks for the response. (1) foo updates a particular User attribute based on a calculation performed on the user.courses collection. I'm listening for the set event on UserCourse objects to trigger foo to update that User attribute, but that

Re: [sqlalchemy] (Semi-)automated way to adjust constraint names via Alembic?

2014-07-02 Thread Mike Bayer
Well you can get at the names that were used in the DB (using Inspector, or reflection) as well as the names that are in your metadata ([constraint for constraint in table.constraints for table in metadata.tables.values()], but as far as matching them up I'm not sure, it depends on what patterns

Re: [sqlalchemy] (Semi-)automated way to adjust constraint names via Alembic?

2014-07-02 Thread Ken Lareau
On Wed, Jul 2, 2014 at 6:44 PM, Mike Bayer mike...@zzzcomputing.com wrote: Well you can get at the names that were used in the DB (using Inspector, or reflection) as well as the names that are in your metadata ([constraint for constraint in table.constraints for table in

[sqlalchemy] Automatically set primary key to None when deleted?

2014-07-02 Thread Paul Molodowitch
Suppose I have a super simple table like this: class Dinosaur(Base): __tablename__ = 'dinosaurs' id = Column(Integer, primary_key=True) name = Column(String(255)) We assume that the id is set up in such a way that by default it always gets a unique value - ie, it uses autoincrement

Re: [sqlalchemy] Automatically set primary key to None when deleted?

2014-07-02 Thread Mike Bayer
On 7/2/14, 10:05 PM, Paul Molodowitch wrote: Suppose I have a super simple table like this: class Dinosaur(Base): __tablename__ = 'dinosaurs' id = Column(Integer, primary_key=True) name = Column(String(255)) We assume that the id is set up in such a way that