[sqlalchemy] [alembic] equivalent to `makemigrations --check`

2024-03-11 Thread Chris Withers
Hi, I got a bounce-back from attempting to email the old alembic google group, so trying here instead! Does Alembic have an equivalent to django's "makemigrations --check"? This is a thing you can use in CI on pull requests to ensure no changes have been made to the model that are not

Re: [sqlalchemy] Re: testing patterns with sqlalchemy 2.0

2022-09-02 Thread Chris Withers
On 01/09/2022 20:00, Jonathan Vanasco wrote: > Create an empty schema from the models using create_all? This is what I usually do with smaller projects. When taking this approach, how do you ensure the accumulated schema migrations end up with a database that matches the one that

[sqlalchemy] testing patterns with sqlalchemy 2.0

2022-08-31 Thread Chris Withers
Hi All, Are there any libraries (or anything in sqlalchemy itself!) that cover the pattern of running unit tests in against a database such that each test gets its own sterile environment in which to run? Postgres, if it helps. I've done some stuff with running in a subtransaction and rolling

Re: [sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-21 Thread Chris Withers
On 20/06/2019 16:00, Mike Bayer wrote: On Thu, Jun 20, 2019, at 3:14 AM, Chris Withers wrote: Hi All, I'm getting this warning: SAWarning: Flushing object with incompatible polymorphic identity ; the object may not refresh and/or load correctly (this warning may be suppressed after 10

Re: [sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-21 Thread Chris Withers
On 20/06/2019 16:00, Mike Bayer wrote: this is not reproducing for me: from sqlalchemy import util import warnings from sqlalchemy import exc warnings.filterwarnings("ignore", category=exc.SAWarning) util.warn_limited(     "Flushing object %s with "     "incompatible polymorphic identity

Re: [sqlalchemy] Re: Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-21 Thread Chris Withers
On 20/06/2019 18:50, Jonathan Vanasco wrote: On Thursday, June 20, 2019 at 3:14:06 AM UTC-4, Chris Withers wrote: How can I indicate in my code that this is intentional and no warning should be omitted? Personal option: I would not mask these.  I would let them persist

Re: merging old versions

2019-06-21 Thread Chris Withers
>> On Thu, Jun 20, 2019 at 2:37 AM Chris Withers > <mailto:ch...@withers.org>> wrote: >> >> Hi All, >> >> I have some versions that make use of the third party package I no >> longer use, how do I collapse down alembic revisions that hav

merging old versions

2019-06-20 Thread Chris Withers
Hi All, I have some versions that make use of the third party package I no longer use, how do I collapse down alembic revisions that have already been executed everywhere? I found https://stackoverflow.com/questions/34491914/alembic-how-to-merge-all-revision-files-to-one-file but that

[sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-20 Thread Chris Withers
Hi All, I'm getting this warning: SAWarning: Flushing object with incompatible polymorphic identity ; the object may not refresh and/or load correctly (this warning may be suppressed after 10 occurrences)     (state_str(state), dict_[polymorphic_key]), I know why: I'm changing the

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-19 Thread Chris Withers
On 10/06/2019 15:40, Mike Bayer wrote: Okay, so sounds like in an ideal world, the framework should provide a way to sub out that transaction middleware when unit testing and then for functional testing, I just need to fall back to dropping everything in the db, or having a fresh db created

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-10 Thread Chris Withers
On 05/06/2019 20:47, Mike Bayer wrote: The panacea I'm after is to be able to run the DDL in a transaction, run each test in a subtransaction off that which is rolled back at the end of each test, but also be able to check that the code under test is doing session.commit() where it should.

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 05/06/2019 17:15, Mike Bayer wrote: How come close() doesn't rollback the SessionTransaction if it throws it away? that's currently what .close() does, it discards the connection.   this is safe because the connection pool ensures transactions are rolled back.   This might have to

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 05/06/2019 16:41, Mike Bayer wrote: Which gives me: $ python sessions_are_weird.py Traceback (most recent call last):   File "sessions_are_weird.py", line 40, in     assert session.query(Event).count() == 0 AssertionError Whereas after the rollback, I'd expect that count to be zero...

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
(sorry, meant to send this to the list) On 05/06/2019 15:52, Mike Bayer wrote: That session.close() appears to be the problem. It's a normal and required part of the code under test, but it throws away the SessionTransaction without rolling it back, so by the time the test does

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Chris Withers
On 04/06/2019 23:21, Mike Bayer wrote: On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: So, how do I roll back the further subtransaction created by the web framework instantiating Session from a sessionmaker bound to the connection in which begin_nested() has been called, which under

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Chris Withers
On 04/06/2019 23:21, Mike Bayer wrote: I'm not following all your code but if there are two sessions in play I'd probably try to avoid that, there should be only one Session you care about. This comes back to something I asked you about on Twitter a while ago: the code under test gets

Re: [sqlalchemy] when does session.transaction come into being?

2019-06-04 Thread Chris Withers
On 04/06/2019 14:47, Mike Bayer wrote: On Tue, Jun 4, 2019, at 3:05 AM, Chris Withers wrote: Hi All, What creates session.transaction? I can't spot get __getattr__ magic, but the only place in the code I see it being created is in .begin(...), which has a docstring saying that it should

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Chris Withers
On 04/06/2019 14:49, Mike Bayer wrote: On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: Now, what I'm trying to test is that I haven't forgotten to include the "with session.transaction". The problem is that, without the transaction.rollback(), the test passes regardless

[sqlalchemy] when does session.transaction come into being?

2019-06-04 Thread Chris Withers
Hi All, What creates session.transaction? I can't spot get __getattr__ magic, but the only place in the code I see it being created is in .begin(...), which has a docstring saying that it should no longer be used, so I feel like I must be missing something? cheers, Chris -- SQLAlchemy -

[sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Chris Withers
Hi All, I'm working with the pattern described at https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites along with pytest and FastAPI, an async web app framework with good support for running blocking code. So,

[sqlalchemy] Will calling a sessionmaker or closing a session block?

2019-06-02 Thread Chris Withers
Hi All, Given this async function (asgi middleware, as it happens): @app.middleware('http') async def make_db_session(request: Request, call_next):     request.state.db = Session()     response = await call_next(request)     request.state.db.close()     return response Would either the call to

Re: [sqlalchemy] context manager for session lifecycle

2018-11-25 Thread Chris Withers
On 26/11/2018 06:15, Mike Bayer wrote: On Sun, Nov 25, 2018 at 12:55 PM Chris Withers wrote: > Soat the moment you can still say this: > > with session.transaction: > > which will do the commit and rollback but not the close(). Po

Re: [sqlalchemy] context manager for session lifecycle

2018-11-25 Thread Chris Withers
On 18/11/2018 23:38, Mike Bayer wrote: On Sun, Nov 18, 2018, 6:22 PM Chris Withers <mailto:ch...@withers.org> wrote: >> Does SQLAlchemy provide a context manager that handles the session >> lifecycle described here? >> https://docs.sqla

Re: [sqlalchemy] context manager for session lifecycle

2018-11-18 Thread Chris Withers
On 16/11/2018 01:09, Mike Bayer wrote: Does SQLAlchemy provide a context manager that handles the session lifecycle described here? https://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#managing-transactions I mean, it should be as simple as the following, right? @contextmanager

[sqlalchemy] context manager for session lifecycle

2018-11-15 Thread Chris Withers
Hi All, I'm sure I've asked this before, but a google through the archives couldn't find it. Does SQLAlchemy provide a context manager that handles the session lifecycle described here? https://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#managing-transactions I mean, it

Re: [sqlalchemy] adding entirely custom constraints

2018-02-01 Thread Chris Withers
awesome, thanks! On 01/02/2018 15:50, Mike Bayer wrote: On Thu, Feb 1, 2018 at 3:27 AM, Chris Withers <ch...@withers.org> wrote: Hi, So, I need to add an exclude constraint to a postgres table which has a boolean column, but: ProgrammingError: (psycopg2.ProgrammingError) data type b

[sqlalchemy] adding entirely custom constraints

2018-02-01 Thread Chris Withers
Hi, So, I need to add an exclude constraint to a postgres table which has a boolean column, but: ProgrammingError: (psycopg2.ProgrammingError) data type boolean has no default operator class for access method "gist" HINT:  You must specify an operator class for the index or define a default

[sqlalchemy] finding all tables with foreign keys to a model

2018-01-29 Thread Chris Withers
Hi All, How can I introspect from a declaratively mapped model all the other models/tables that have foreign keys to it? This keeps like something the ORM layer must know about... cheers, Chris -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/

Re: unit testing migration code

2017-12-14 Thread Chris Withers
g_one()" 4. drops the database and...that's how you do it ! On Thu, Nov 30, 2017 at 1:54 PM, Chris Withers <ch...@simplistix.co.uk> wrote: Hi All, How would I add test coverage for this sort of code? https://coveralls.io/builds/14408741/source?filename=mortar_mixins%2Fmigrations.py

Re: [PossibleSpam][5.0] Re: [sqlalchemy] Concise, Pythonic query syntax

2017-11-06 Thread Chris Withers
ell. Looking, I see that SQLAlchemy is MIT-license, so I can re-license it to that. Bryan On Mon, Nov 6, 2017 at 12:25 PM, Chris Withers <ch...@withers.org <mailto:ch...@withers.org>> wrote: Great looking library, shame about the license. You parti

Re: [sqlalchemy] Concise, Pythonic query syntax

2017-11-06 Thread Chris Withers
Great looking library, shame about the license. You particularly attached to GPL3 or would you be amenable to BSD or MIT? Chris On 03/11/2017 21:52, Bryan Jones wrote: All, I've just released the pythonic_sqlalchemy_query package on PyPI, which provides concise, Pythonic query syntax for

Re: [sqlalchemy] mapper.order_by deprecated?

2017-05-09 Thread Chris Withers
) s.query(A.id, B.id) s.query(B.id, A.id) etc On 05/08/2017 06:21 AM, Chris Withers wrote: Hi All, I see mapper.order_by is deprecated in the latest release. Why is that? cheers, Chris -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

[sqlalchemy] mapper.order_by deprecated?

2017-05-08 Thread Chris Withers
Hi All, I see mapper.order_by is deprecated in the latest release. Why is that? cheers, Chris -- 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

Re: adding an auto increment column to an existing table

2017-01-18 Thread Chris Withers
On 17/01/2017 15:07, mike bayer wrote: Because there's no data in a brand new table, the server default isn't needed to create the not-null column. No needed, but it is created, isn't that the point of autoincrement=True? for postgresql, autoincrement=True means that if the column is

Re: [sqlalchemy] Selecting from polymorphic tables without selecting polymorphic columns

2017-01-17 Thread Chris Withers
On 17/01/2017 18:38, mike bayer wrote: On 01/17/2017 01:05 PM, Chris Withers wrote: Potentially related issue, given: class TheTable(Base): __tablename__ = 'stuff' __mapper_args__ = dict( polymorphic_on='type', polymorphic_identity='base', ) type = Column

Re: [sqlalchemy] Selecting from polymorphic tables without selecting polymorphic columns

2017-01-17 Thread Chris Withers
Potentially related issue, given: class TheTable(Base): __tablename__ = 'stuff' __mapper_args__ = dict( polymorphic_on='type', polymorphic_identity='base', ) type = Column(String) col = Column(String) class Model1(TheTable): __mapper_args = dict(

Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-17 Thread Chris Withers
On 17/01/2017 15:08, mike bayer wrote: On 01/17/2017 06:15 AM, Chris Withers wrote: Great, thanks. I assume has_inherited_table returns False where the table is defined on the class itself? it looks like has_inherited_table is just looking for non-None __table__ attribute up the inheritance

Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-17 Thread Chris Withers
his: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.has_inherited_table this might be better since you're really looking for a "table" up above On 01/16/2017 12:05 PM, Chris Withers wrote: Hi All, If I'm using instrument_class events to

[sqlalchemy] single table inheritance and instrument_class events

2017-01-16 Thread Chris Withers
Hi All, If I'm using instrument_class events to add some constraints to a table, what's the 'right' way to spot when it's a subclass is being instrumented? (where I'm guessing I shouldn't add the constraints). My current attempt is here:

Re: adding an auto increment column to an existing table

2017-01-10 Thread Chris Withers
le_name='observation') op.create_primary_key('observation_pkey', 'observation', ['id']) ...but how come my original attempt didn't? cheers, Chris On 10/01/2017 08:03, Chris Withers wrote: So, I screwed up and realised I really want an auto-incrementing integer as the primary key for a bu

adding an auto increment column to an existing table

2017-01-10 Thread Chris Withers
So, I screwed up and realised I really want an auto-incrementing integer as the primary key for a bunch of tables. I've changed my models, got all the tests passing and now I need to get the migrations done, I have: op.add_column('observation', sa.Column('id', sa.Integer(),

Re: [sqlalchemy] Load sqlalchemy orm model from dict

2017-01-07 Thread Chris Withers
On 07/01/2017 00:20, Daniel Kraus wrote: Hi! mike bayer writes: you're looking for session.merge() but if you're looking to save on a SELECT you might also want to send in load=False - and if you are starting with a fresh (non-pickled) object you probably need to

Re: patterns for automated tests of migrations

2016-12-11 Thread Chris Withers
more elaborate tests involving actual data, this should be a good starting point, though HTH, tom On 23 Nov 2016, at 10:15, Chris Withers <ch...@simplistix.co.uk> wrote: Hi All, How do you go about writing automated tests for a migration? I don't often do this, but when migrations

Re: [sqlalchemy] regression with 1.1.0

2016-10-08 Thread Chris Withers
People use pg8000? ;-) I jest, but under what circumstances does pg8000 make a better choice that psycopg2? Chris On 07/10/2016 14:40, mike bayer wrote: FYI pg8000 raises ProgrammingError on these On 10/07/2016 08:56 AM, Mike Bayer wrote: On 10/07/2016 02:36 AM, Chris Withers wrote

Re: [sqlalchemy] regression with 1.1.0

2016-10-07 Thread Chris Withers
On 06/10/2016 15:04, Mike Bayer wrote: So Mortar seems to be a heavily SQLAlchemy-integrated product. It has a very small user base ;-) I'd like to point out that whenever we do these year-long release cycles, I put out a lot of betas very early on that hopefully contain all the biggish

[sqlalchemy] regression with 1.1.0

2016-10-06 Thread Chris Withers
Hi All, Since 1.1.0 was released yesterday, one of my library's nightly builds have started failing: https://travis-ci.org/Mortar/mortar_mixins/jobs/165422873 Error was: AssertionError: CompileError(u"Column 'model.period' is marked as a member of the primary key for table 'model', but has

Re: [sqlalchemy] changing the order of columns in primary keys, including when generated by mixins

2016-09-22 Thread Chris Withers
On 22/09/2016 14:55, Mike Bayer wrote: On 09/22/2016 07:30 AM, Chris Withers wrote: How do you control the order in which columns are added to a multi-column primary key when using the declarative primary_key=True syntax? How about when one of those columns comes from a mixin? without mixins

[sqlalchemy] changing the order of columns in primary keys, including when generated by mixins

2016-09-22 Thread Chris Withers
Message Subject: Re: [GENERAL] performance problems with bulk inserts/updates on tsrange with gist-based exclude constrains Date: Mon, 19 Sep 2016 09:41:33 -0700 From: Jeff Janes <jeff.ja...@gmail.com> To: Chris Withers <ch...@simplistix.co.uk> CC: pgsql-general

Re: [sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Chris Withers
wrote: import warnings warnings.simplefilter("error") On 09/15/2016 08:07 AM, Chris Withers wrote: Hi All, How can I turn SAWarnings into exceptions? I'm struggling with what to put into the PYTHONWARNINGS environment variable :-S cheers, Chris -- You received this message b

[sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Chris Withers
Hi All, How can I turn SAWarnings into exceptions? I'm struggling with what to put into the PYTHONWARNINGS environment variable :-S cheers, Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop

Re: [sqlalchemy] reflecting stored procedure names, enums, and the like

2016-08-16 Thread Chris Withers
ou're just looking for a "drop everything" method I'd probably forego all that boilerplate and just have "drop_pg_sps", "drop_mysql_sps", etc. functions and key them off of engine.name in a dictionary or something. On 08/15/2016 06:16 AM, Chris Withers wrote:

[sqlalchemy] reflecting stored procedure names, enums, and the like

2016-08-15 Thread Chris Withers
Hi All, What's the best way (preferably database agnostic) to reflect stored procedure names, enums names and other non-table-specific items? I'm trying to improve this function, which is based on Mike's original recipe:

[sqlalchemy] chide 2.0.1 released!

2016-06-16 Thread Chris Withers
Hi All, I'm please to announce a new release of chide, a tiny library for building sample objects. This release includes the following: - Fix nasty bug when using with sqlalchemy where related objects could get added to the session even though they were never requested, as a result of a

[sqlalchemy] Re: plain text versus html mail

2016-04-22 Thread Chris Withers
On 22/04/2016 03:04, Ben Finney wrote: Chris Withers <ch...@simplistix.co.uk> writes: [no text body] When posting to mailing lists, please be sure to have a plain text body with the full information. Not everyone wants to enable HTML in email just to read a software announcement :-)

[sqlalchemy] chide 2.0.0 released! - sample objects for tests

2016-04-21 Thread Chris Withers
Hi All, I've just released a new version of this tiny library for making sample objects for testing. Here's a SQLAlchemy example: class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) child_id = Column(Integer,

Re: [sqlalchemy] where is InstanceState.key set?

2016-04-21 Thread Chris Withers
:28 PM, Chris Withers wrote: Hey All, Where is InstanceState.key set? I'm looking for the code that builds the key used in the identity_map of the session. Turns out to be not so easy to find... Chris -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] where is InstanceState.key set?

2016-04-20 Thread Chris Withers
Hey All, Where is InstanceState.key set? I'm looking for the code that builds the key used in the identity_map of the session. Turns out to be not so easy to find... Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from

[sqlalchemy] tiny new tool for making sample objects for tests

2016-04-14 Thread Chris Withers
Hi All, I've just released this tiny library for making sample objects for testing. Here's a SQLAlchemy example: class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) child_id = Column(Integer,

Re: [sqlalchemy] in-place modification of queries?

2015-12-30 Thread Chris Withers
, Chris On 28/12/2015 15:22, Mike Bayer wrote: not through the current API, no. you'd need to write some modifier to the @generative decorator and basically tinker with things to make it do that. On 12/28/2015 06:18 AM, Chris Withers wrote: Hi All

[sqlalchemy] in-place modification of queries?

2015-12-28 Thread Chris Withers
Hi All, Is there anything I can do to make Query instance non-generative? query = session.query(Foo) query.filter(Foo.x==1) ...and have the query actually be modified rather than returning a new query with the clause added? cheers, Chris -- You received this message because you are

Re: [sqlalchemy] can I use tables generated by ORM via sql expression language for select queries

2015-12-27 Thread Chris Withers
On 27/12/2015 04:44, Krishnakant wrote: Hi, The subject says it all. I have classes inheriting the base and thus my tables are created using ORM. But I wish to use sql expression language for queries, particularly bulk selects for faster performance. So is this possible and how? Sure, you

[sqlalchemy] postgres "similar to" in sqlalchemy expressions

2015-12-11 Thread Chris Withers
Hi All, Just wanted to double check, is this still the best way to do this: https://groups.google.com/forum/#!topic/sqlalchemy/6kZaWeqTpHA foo.op("SIMILAR TO")(bar) cheers, Chris -- You received this message because you are

Re: [sqlalchemy] Re: set next value of postgres sequence

2015-12-01 Thread Chris Withers
Indeed, but that's not quite what I asked ;-) I'm after setting the next value using, eg, setval: http://www.postgresql.org/docs/current/static/functions-sequence.html ...or to do it on creation of the sequence: http://www.postgresql.org/docs/current/static/sql-createsequence.html I guess

Re: [sqlalchemy] non-table DDL elements and MetaData objects

2015-12-01 Thread Chris Withers
Does the .listen example there work or does it need the patch to land? On 01/12/2015 21:47, Jonathan Vanasco wrote: I think this story may have some related info - https://bitbucket.org/zzzeek/sqlalchemy/issues/3442/no-control-of-ddl-sequences-for-indexes-fk disclaimer -- I merely saw this

Re: [sqlalchemy] non-table DDL elements and MetaData objects

2015-12-01 Thread Chris Withers
On 02/12/2015 00:08, Mike Bayer wrote: On 12/01/2015 02:49 PM, Chris Withers wrote: - once at 'database creation' time, so set up some stored procedures. (I know SQLAlchemy doesn't create databases itself, so interested in the correct approach for this) So, thinking this through

Re: [sqlalchemy] after_create event for all uses of a mixin

2015-12-01 Thread Chris Withers
On 01/12/2015 10:10, Simon King wrote: On Tue, Dec 1, 2015 at 8:17 AM, Chris Withers <ch...@simplistix.co.uk <mailto:ch...@simplistix.co.uk>> wrote: Hi All, Where can I find documentation on the parameters taken by event.listen? I have some listeners on inst

Re: [sqlalchemy] non-table DDL elements and MetaData objects

2015-12-01 Thread Chris Withers
On Tue, Dec 1, 2015 at 8:17 AM, Chris Withers <ch...@simplistix.co.uk <mailto:ch...@simplistix.co.uk>> wrote: I'm also looking for two events to listen to: - once at 'database creation' time, so set up some stored procedures. (I know SQLAlchemy doesn't create database

[sqlalchemy] event.listen questions

2015-12-01 Thread Chris Withers
Hi All, Where can I find documentation on the parameters taken by event.listen? I have some listeners on instrument_class that pass propagate=True, but I can't find docs on what that means? I'm also looking for two events to listen to: - once at 'database creation' time, so set up some

[sqlalchemy] set next value of postgres sequence

2015-11-27 Thread Chris Withers
Hi All, What's the recommended way to set the next value of a postgres sequence when using sqlalchemy? cheers, Chris -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an

Re: [sqlalchemy] best mysql dialect?

2015-11-15 Thread Chris Withers
AM, Chris Withers wrote: Hello, What's the best mysql dialect to use nowadays? python-python aka mysqldb used to be my favourite, but the c extensions make for some sadness. I was happily using ​mysql-connector-python-rf, but 2.1.3 was released today which appears to have broken the ability

[sqlalchemy] best mysql dialect?

2015-11-13 Thread Chris Withers
Hello, What's the best mysql dialect to use nowadays? python-python aka mysqldb used to be my favourite, but the c extensions make for some sadness. I was happily using ​mysql-connector-python-rf, but 2.1.3 was released today which appears to have broken the ability to pip install it. So,

[sqlalchemy] getting the identity for objects not in a session

2015-10-08 Thread Chris Withers
Hi All, Reading http://docs.sqlalchemy.org/en/rel_1_0/orm/internals.html?highlight=identitymap#sqlalchemy.orm.state.InstanceState.identity I can understand why a new object not in a session won't have an identity. However, that had me wondering, when a new object is added to the session, how

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-10-01 Thread Chris Withers
On 26/09/2015 21:15, Mike Bayer wrote: On 9/25/15 12:24 PM, Chris Withers wrote: On 25/09/2015 13:58, Mike Bayer wrote: session.query(A).filter(A.id>10).as_at(now)) you'd need to subclass Query and dig into Query.column_descriptions to get at the existing entities, then add

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
On 25/09/2015 13:58, Mike Bayer wrote: session.query(A).filter(A.id>10).as_at(now)) you'd need to subclass Query and dig into Query.column_descriptions to get at the existing entities, then add all that criterion. remind me where the docs are for plugging in a subclassed Query into a

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
On 25/09/2015 16:35, Jonathan Vanasco wrote: fwiw, I struggled with this a while back and then gave up. i ended up writing a few filter__xyz() functions that accept/return a query. in the def, I join needed tables and filter. instead of inspecting the query for tables, I just pass in some

[sqlalchemy] "No such event 'instrument_class' for target" for mixin that needs to listen to 'instrument_class'

2015-09-25 Thread Chris Withers
Hi All, I have a mixin class here that I've factored out of one project as I want to use it in another one: https://github.com/Mortar/mortar_mixins/blob/master/mortar_mixins/temporal.py The problem is that importing the module seems to result in the following exception being raised: >>>

[sqlalchemy] funk session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
Hi All, Suppose I have the following: from sqlalchemyimport Column, Integer, Text, ForeignKey, and_ from sqlalchemy.dialects.postgresqlimport TSRANGEas Range from sqlalchemy.ext.declarativeimport declarative_base Base = declarative_base() class A(Base): id =

[sqlalchemy] views

2015-09-25 Thread Chris Withers
Hi All, Is this still the best way to hand views, or are there later and greater things in 1.0+? https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views How would I make a view behave like a normal declarative class (column attributes, etc), but while still having it create itself

[sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Chris Withers
Hi All, Suppose I have the following: from sqlalchemy import Column, Integer, Text, ForeignKey, and_from sqlalchemy.dialects.postgresql import TSRANGE as Rangefrom sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): id = Column(Integer(),

Re: [sqlalchemy] views

2015-09-25 Thread Chris Withers
Also forgot to ask... What's support like in Alembic for creating views (especially if the views are described by a declarative class as I'm looking for below...) > On 25 Sep 2015, at 08:13, Chris Withers <ch...@simplistix.co.uk> wrote: > > Hi All, > > Is this still

[sqlalchemy] "No such event 'instrument_class' for target" for mixin that needs to listen to 'instrument_class'

2015-09-24 Thread Chris Withers
Hi All, I have a mixin class here that I've factored out of one project as I want to use it in another one: https://github.com/Mortar/mortar_mixins/blob/master/mortar_mixins/temporal.py The problem is that

Re: [sqlalchemy] "No such event 'instrument_class' for target" for mixin that needs to listen to 'instrument_class'

2015-09-24 Thread Chris Withers
On 24/09/2015 19:31, Mike Bayer wrote: sqlalchemy.exc.InvalidRequestError: No such event 'instrument_class' for target '' you need to make sure SQLAlchemy ORM is at least imported when that event handler is called and also you'd need to make sure propagate=True is on it because it's only a

[sqlalchemy] session context manager

2015-07-28 Thread Chris Withers
Hi All, I'm looking to use a session as a context manager, I've found session_scope here: http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#when-do-i-construct-a-session-when-do-i-commit-it-and-when-do-i-close-it ...but is there anything in the core? I find of expected a session

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-18 Thread Chris Withers
On 17/02/2015 18:43, Javier Pajuelo wrote: The weird part is that I just checked my candidates table and I see no duplicates. However, during the generation of a report that ties candidates, jobs, and events, I get duplicate candidates. My suspicion is that it's your code which does the

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Chris Withers
What does the code look like that generates 'candidates'? Chris On 17/02/2015 00:48, Javier Pajuelo wrote: I get the following error: | sqlalchemy.exc.IntegrityError: (IntegrityError) column id is not unique u'INSERT INTO candidates (id, timeStamp, name, link) VALUES (?, ?, ?, ?)'

Re: [sqlalchemy] ValidityTime Column

2014-11-28 Thread Chris Withers
You should have a look at the Postgres range types in PG 9.2+... Chris On 27/11/2014 10:44, Giovanni Cavallero wrote: Hi Michael, many thanks for your help! Is there any way to do this in an automatic way? I mean now i have the following code from sqlalchemy import * from

Re: [sqlalchemy] manual connection management interacting badly with sessions

2014-11-11 Thread Chris Withers
On 07/11/2014 21:30, Michael Bayer wrote: So, turns out the pandas.io.sql.read_frame in the version of pandas I'm using has a con.commit() in it. wtf?! Guess I'll raise that as a bug in Pandas if they haven't fixed it in a subsequent release… didn’t pandas introduce SQLAlchemy

[sqlalchemy] manual connection management interacting badly with sessions

2014-11-07 Thread Chris Withers
Hello, So, short version: if I need a raw DBAPI connection and I have a SQLAlchemy Session, what's the correct way to manage that raw connection if I get it using session.connection().connection? Versions: Postgres 9.2 SQLAlchemy 0.8.2 Background: I want to create a DataFrame using

Re: [sqlalchemy] manual connection management interacting badly with sessions

2014-11-07 Thread Chris Withers
On 07/11/2014 14:14, Michael Bayer wrote: session.connection().connection is the same connection that session.rollback() will be referring towards. though when you have that DBAPI connection (it is in fact still wrapped by ConnectionFairy), you shouldn’t call commit() or rollback() on that

[sqlalchemy] databases and asynchronous programming

2014-03-09 Thread Chris Withers
Hi All, So, one of the projects I'm playing with at the moment is a big ball of asynchronous networking (tonnes of protocols, some tcp, some multicast) which I want to stick a webapi onto (normal requests + websocket) and probably do some database interaction with. So, aside from figuring

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-03-03 Thread Chris Withers
://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.get_bind http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.params.binds Would that work in your situation? Simon On Wed, Feb 26, 2014 at 12:50 PM, Chris Withers ch

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-03-03 Thread Chris Withers
Hi Jonathan, On 03/03/2014 17:22, Jonathan Vanasco wrote: Yep. You can look at the internals of the 'Transaction' package and cross reference to the zope.sqlachemy to see exactly how it works. Sorry, not sure if I'm following you, but I'm talking about Simon's suggestion only to use a

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-02-26 Thread Chris Withers
a single session, like the example at: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#enabling-two-phase-commit Simon On Tue, Feb 25, 2014 at 6:07 PM, Chris Withers ch...@simplistix.co.uk wrote: No takers? :'( On 19/02/2014 18:43, Chris Withers wrote: Hi All, My other usual

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-02-25 Thread Chris Withers
No takers? :'( On 19/02/2014 18:43, Chris Withers wrote: Hi All, My other usual question now ;-) I have multiple databases that I'm connecting to from my application. I need to commit or rollback a single transaction across all of them. So, two phase commit, right? Okay, but how do I tie

Re: [sqlalchemy] TypeError: Range objects cannot be ordered in flush

2014-02-23 Thread Chris Withers
On 24/12/2013 21:21, Ryan Kelly wrote: IMO psycopg2's implementation should be patched, since they basically just didn't implement ordering. PostgreSQL itself has no problem ordering range types (though the ordering is somewhat arbitrary):

[sqlalchemy] tying multiple sessions together with one transaction

2014-02-19 Thread Chris Withers
Hi All, My other usual question now ;-) I have multiple databases that I'm connecting to from my application. I need to commit or rollback a single transaction across all of them. So, two phase commit, right? Okay, but how do I tie the sessions together? What and how do I call commit? Is

[sqlalchemy] declarative polymorphic inheritance abstraction problem

2014-02-10 Thread Chris Withers
Hi All, I'm trying to be efficient with my code, but it seems to tripping SQLAlchemy up. So, basically I want to have a schema with two tables, content and project, to represent two three types of object: - article has a set of fields as found in the 'content' table - project has fields

[sqlalchemy] TypeError: Range objects cannot be ordered in flush

2013-12-24 Thread Chris Withers
Hi All, I feel like I've asked this before but apologies, I cannot find the previous thread. So, when using the support for psycopg2's range types I added, I sometimes see the following during a flush: File

Re: [sqlalchemy] full outer join?

2013-12-02 Thread Chris Withers
- why ? On Dec 1, 2013, at 5:08 PM, Chris Withers ch...@simplistix.co.uk wrote: This feels like a newbie question, but how would I do a full outer join in SQLAlchemy? Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- You

Re: [sqlalchemy] creating a cte from a string and some params

2013-12-01 Thread Chris Withers
a patch: http://www.sqlalchemy.org/trac/ticket/2877 it’s quite short. I just don’t like the current contract of SelectBase, which has many methods that don’t apply here, so might want to rework the base classes. On Nov 22, 2013, at 5:06 AM, Chris Withers ch...@simplistix.co.uk wrote: On 21

  1   2   3   4   5   >