[sqlalchemy] SQLAlchemy utility function to evaluate a string

2018-03-15 Thread Josh
k to avoid circular imports.) In other words, is there a function that can do `model_cls = looup_model(model_name)`? Thanks, Josh -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and

[sqlalchemy] MySQL tx_isolation fixed in 1.1 but not in 1.2

2017-12-01 Thread Josh Anyan
commit and apply it yourself? -- Josh A. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.

[sqlalchemy] Intermittent ObjectDeletedErrors

2015-10-21 Thread Josh Jaques
Hey I'm getting some intermittent ObjectDeletedError's that I don't really understand. The code I use looks like this: > DBSession.begin() > instance = DBSession.query(OrmOjbect).get("primary_key") > DBSession.rollback() > > > x = instance.attribute1 Probably 90% of the time the

[sqlalchemy] Re: Intermittent ObjectDeletedErrors

2015-10-21 Thread Josh Jaques
of the instance. On Wednesday, October 21, 2015 at 4:11:32 PM UTC-5, Josh Jaques wrote: > > Hey I'm getting some intermittent ObjectDeletedError's that I don't really > understand. > > > The code I use looks like this: > > >> DBSession.begin() >> instance = DBSessi

[sqlalchemy] Re: SQLAlchemy Netezza Dialect

2014-04-08 Thread Josh Kuhn
I created an actual repo for this, so if anyone finds bugs, or wants to submit patches: https://github.com/deontologician/netezza_sqlalchemy On Tue, Mar 4, 2014 at 7:18 PM, Josh Kuhn deontologic...@gmail.com wrote: Since there wasn't one out there already, I took a shot at it. It's really

[sqlalchemy] Replacing a single column in a select (Core language)

2014-03-27 Thread Josh Kuhn
I have a situation where I need to produce a select object, and then later, one of the fields needs to be zeroed out conditionally. so something like: def select_ab(param): from_obj = join(A, B, A.c.b == B.c.b) return select([A.c.a, B.c.b, B.c.d], from_obj=from_obj).where(A.c.a == param)

Re: [sqlalchemy] Replacing a single column in a select (Core language)

2014-03-27 Thread Josh Kuhn
...@zzzcomputing.comwrote: On Mar 27, 2014, at 10:08 AM, Josh Kuhn deontologic...@gmail.com wrote: I have a situation where I need to produce a select object, and then later, one of the fields needs to be zeroed out conditionally. so something like: def select_ab(param): from_obj = join

[sqlalchemy] SQLAlchemy Netezza Dialect

2014-03-04 Thread Josh Kuhn
distribute on clauses to create table statements, and ensuring limit clauses don't get sql params (since it doesn't like that). With pandas incorporating SQLA, I figure this might be useful to some people out there. --Josh -- You received this message because you are subscribed to the Google Groups

Re: [sqlalchemy] Association proxy info property (or lack thereof)

2014-02-24 Thread Josh Kuhn
Thanks for the reply! I'll add the info property. Glad to see I wasn't going about this completely the wrong way On Sun, Feb 23, 2014 at 1:16 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 23, 2014, at 12:59 AM, Josh Kuhn deontologic...@gmail.com wrote: I'm writing some code

[sqlalchemy] Association proxy info property (or lack thereof)

2014-02-22 Thread Josh Kuhn
I'm writing some code to serialize some SA models to JSON, and for columns and relationships, it's convenient to tag which fields should be serialized with the info dictionary like so: class Thing(Base): id = Column(Integer, primary_key=True, info={'jsonify': False}) name = Column(String,

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Josh Kuhn
I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships On Thu, Feb 13, 2014 at 12:04 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 13,

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Josh Kuhn
I don't know if this is what you're thinking, but you can also just build a query object in different ways if you want to query = session.query(Study).options( joinedload(Study.system), joinedload(Study.site)).

[sqlalchemy] Relationships using max

2014-01-31 Thread Josh Kuhn
I've got a two tables I'd like to create a relationship for. One is the object, and another tracks versions. Here's a gist with the setup: https://gist.github.com/deontologician/8744532 Basically, the object doesn't have a direct reference to the current version stored in the table. Instead, the

[sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
I'm trying to get a certain access pattern to work and I need a bit of help: https://gist.github.com/deontologician/5922496 What I'm trying to do is use an association proxy to create a view of a collection that looks like a list of dictionaries (for serializing to json). I also want to update

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
I've attempted the following: from sqlalchemy import Column, Integer, String, ForeignKey, create_engine from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.event import listen from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.associationproxy import

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
On Wed, Jul 3, 2013 at 7:30 PM, Michael Bayer mike...@zzzcomputing.comwrote: @event.listens_for(Gadget, before_insert) def before_gadget(mapper, connection, target): target.machine_id = target.widget.machine_id 2. when widget is updated, gadgets need new machine_id, here UPDATE is

Re: [sqlalchemy] My mapped tables are missing insert, update methods

2013-06-07 Thread Josh Kuhn
Your User class is mapped to a Table. It's not the Table itself. To get the update method, you need to access User.__table__.update On Fri, Jun 7, 2013 at 4:12 PM, Michael Nachtigal michael.nachti...@catalinamarketing.com wrote: After reading the documentation, I am under the impression that

[sqlalchemy] already has a primary mapper defined error occurs occasionally

2012-01-10 Thread Josh Ha-Nyung Chung
I'm running web service using sqlalchemy with apache + wsgi + pyramid framework. I've initialize metadata like the following: Base = declarative_base() Base.metadata.reflect(bind=my_engine) user_table = DP_Base.metadata.tables[user] mapper(User, user_table) and I'm using scoped session since

Re: [sqlalchemy] already has a primary mapper defined error occurs occasionally

2012-01-10 Thread Josh Ha-Nyung Chung
User class extends object, not Base. Actually User class is imported from another package, which is made by my coworker, and I need to separate my work from his. So I have no choice but using classical mapping since the User class is intended to be used with classical mapping. -- Josh Ha

[sqlalchemy] InvalidRequestError: Can't reconnect until invalid transaction is rolled back error during SELECT query

2011-12-28 Thread Josh Ha-Nyung Chung
I've made web application using Pyramid 1.2.5 + Python 2.7.1 + SQLAlchemy 0.7.4 and occasionally encountered the following error. Traceback (most recent call last): File /usr/local/lib/python2.7/site-packages/pyramid/router.py, line 176, in __call__ response = self.handle_request(request)

[sqlalchemy] sequence incrementing

2011-02-04 Thread Josh Stratton
I'm connecting to an Oracle database for my work and we do replication by periodically joining tables across sites instead of a single server just in case a link in between goes down. One issue with this though is I need to generate unique keys for a single table so if the connection does go

Re: [sqlalchemy] sequence incrementing

2011-02-04 Thread Josh Stratton
that you're using table.create(), metadata.create_all(), or sequence.create() to issue the CREATE SEQUENCE call.   The INCREMENT BY and START WITH clauses should be emitted as of the 0.6 series of SQLAlchemy. On Feb 4, 2011, at 2:10 PM, Josh Stratton wrote: I'm connecting to an Oracle database

[sqlalchemy] simple update without a session or mapping

2011-01-26 Thread Josh Stratton
I'm currently interfacing with an Oracle db using sqlalchemy without any sessions or mappings. Selects and inserts work great, but I'd like to be able to update a row without having to delete and reinsert it. # remove the id table.delete(table.c.id == row['id']).execute()

[sqlalchemy] Joined Table Inheritance and Mapping:Child classes do not pick up maps to other tables

2010-04-06 Thread Josh Winslow
I'm attempting to use joined table polymorphism for various types of activities. Activities all share a few common features, a location, a reference number, time, etc. but some have some further attributes. When I set up my map like so: mapper(Activity, activities,

[sqlalchemy] Re: Joined Table Inheritance and Mapping:Child classes do not pick up maps to other tables

2010-04-06 Thread Josh Winslow
On Apr 6, 4:27 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 6, 2010, at 3:56 PM, Josh Winslow jwins...@gmail.com wrote: I'm attempting to use joined table polymorphism for various types of activities.  Activities all share a few common features, a location, a reference number

[sqlalchemy] Re: attempting something like a bulk insert ignore

2009-10-22 Thread Josh Stratton
you'd need to establish the primary key from the mapper's point of view in terms of both userId and userName.   mapper() accepts a primary_key argument for this purpose. That kind of surprises me sqlalchemy isn't aware of what's a primary key and what isn't. Looking at the docs, it states

[sqlalchemy] Re: attempting something like a bulk insert ignore

2009-10-22 Thread Josh Stratton
OK, you have the unique constraint on userName alone.  that means that you *cannot* have two rows like this: userId      userName 1           someuser 2           someuser Right. because unlike a primary key that consists of userId and userName, the distinctness here of userName is

[sqlalchemy] Re: purpose of class_mapper

2009-10-21 Thread Josh Stratton
I just figured the mapper had to be called every time as it didn't just compile the class, but actually needed a database table to map to and wasn't sure what was done under the hood to setup that up and if it was valid for another database. Just to be sure, but would using a mapper setup as

[sqlalchemy] Re: attempting something like a bulk insert ignore

2009-10-21 Thread Josh Stratton
From what I've read of sqlalchemy, I originally wanted to have a main table with one attribute foreign keyed to another table's autoincremented integer primary key userId and a userName.  I thought I could join the tables together and set that as the mapper.  The save every object in my

[sqlalchemy] Re: attempting something like a bulk insert ignore

2009-10-21 Thread Josh Stratton
this is always easily worked around by specifing the ON clause to your join(), as the second argument of table1.join(table2, and_(table1.c.foo==table2.c.bar, table1.c.bat==table2.c.hoho, ...)). Ah, okay. No foreign key, just a join. For reference, this was what I ended up going with. j =

[sqlalchemy] Re: attempting something like a bulk insert ignore

2009-10-21 Thread Josh Stratton
2. load-each-row-at-a-time just remove the first query.  the session will then look up things using merge() as you ask. But wouldn't this still cause an insertion error when I try merging a job object, who's userName is already in the table?

[sqlalchemy] Re: purpose of class_mapper

2009-10-20 Thread Josh Stratton
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:             #

[sqlalchemy] Re: purpose of class_mapper

2009-10-20 Thread Josh Stratton
popular, since it performs both at the same time by definition. Okay, that seemed to work. Thanks. A mapper() call followed by a class_mapper() call for each database did the trick. Josh --~--~-~--~~~---~--~~ You received this message because you are subscribed

[sqlalchemy] Re: purpose of class_mapper

2009-10-20 Thread Josh Stratton
AttributeError: 'MyObject' object has no attribute '_state' I don't see any _state printed out.  The only additional attribute I see is the 'c' variable, where pull tables from.  What is causing this _state thing to appear?  Do I need to call class_mapper after each mapper only only once

[sqlalchemy] Re: Rollback error in the first query of the session.

2009-04-03 Thread Josh Winslow
On Apr 2, 9:21 pm, Michael Bayer zzz...@gmail.com wrote: On Apr 2, 4:41 pm, Josh Winslow jwins...@gmail.com wrote: This is the stack trace: ⇝  InvalidRequestError: The transaction is inactive due to a rollback in a subtransaction. Issue rollback() to cancel

[sqlalchemy] Re: Rollback error in the first query of the session.

2009-04-03 Thread Josh Winslow
On Apr 3, 10:13 am, Michael Bayer mike...@zzzcomputing.com wrote: Josh Winslow wrote: On Apr 2, 9:21 pm, Michael Bayer zzz...@gmail.com wrote: On Apr 2, 4:41 pm, Josh Winslow jwins...@gmail.com wrote: This is the stack trace: ⇝  InvalidRequestError

[sqlalchemy] Rollback error in the first query of the session.

2009-04-02 Thread Josh Winslow
I'm currently suffering from a rare and hard to pin down bug that seems to be living somewhere in contextual session code. As part of a formencode schema, I'm checking to make sure that a submitted form value matches a record in the database. From tracing through the request lifecycle, it