Re: [sqlalchemy] association proxy and eager loading

2015-12-18 Thread Jonathan Vanasco
Thanks Simon! I tried your method and it didn't work... because I had been resetting my query all along and not noticing (!!!) FFS. After extensive testing this morning, I found that mistake because these 3 forms will generate the same exact sql in the current 1.x release: # Chained

[sqlalchemy] association proxy and eager loading

2015-12-17 Thread Jonathan Vanasco
I'm trynig to use association_proxy to map a collection of items through an intermediary table I'm running into a problem where I can't figure out a way to eagerload the collection through the extension. if i do: query.options(joinedload('to_items', 'to_items.item')) I can loop

[sqlalchemy] Re: how to use postgresql json type in sql expression language

2015-12-11 Thread Jonathan Vanasco
http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSON -- 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 email to

Re: [sqlalchemy] Determination of string lengths

2015-12-10 Thread Jonathan Vanasco
`sqlalchemy.func` does not map anything. It is a namespace for a factory generator. anything you access with it becomes a function of that caller's name. for example: filter( func.foo(table.column) > 1 ) produces WHERE foo(table.column) > 1 sqlalchemy generates the `foo`

[sqlalchemy] Re: How to refer to fields in nested queries?

2015-12-08 Thread Jonathan Vanasco
If you don't use a subquery, you can use the `desc("column")` in `sqlalchemy`. (there is an `asc()` as well). Below I use `label('name')` to specify the result column name for computed field, then order by it. results = dbSession.query( model.Foo.a,

[sqlalchemy] Re: How to refer to fields in nested queries?

2015-12-08 Thread Jonathan Vanasco
On Tuesday, December 8, 2015 at 12:14:46 PM UTC-5, SF Markus Elfring wrote: > > Will it become easier to recognise the relevant relationships > from the corresponding programming interface documentation? > You should read through the tutorial/narrative documentation on the ORM and "Core", as

[sqlalchemy] Re: Selection of sort directions

2015-12-05 Thread Jonathan Vanasco
Odd- this isn't the narrative docs You can use column attributes... (http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement.desc) session.query(model.Foo).order_by(model.Foo.id.desc()) session.query(model.Foo).order_by(model.Foo.id.asc())

[sqlalchemy] Re: inserts rows in wrong order

2015-12-04 Thread Jonathan Vanasco
Sorry, hadn't finished my morning coffee and this "registered" as a dict ordering. Without seeing code, it's hard to understand what is going on. Here's my guess: * When you call the insert(), the `output_batch` is inserted into the DB in that order. This is expected and you should see that

[sqlalchemy] Re: inserts rows in wrong order

2015-12-04 Thread Jonathan Vanasco
Python dictionars do not preserve the order. You could try using an OrderedDict https://docs.python.org/2/library/collections.html -- 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,

Re: [sqlalchemy] Re: inserts rows in wrong order

2015-12-04 Thread Jonathan Vanasco
Yeah, you need an "id" field to do that and "ORDER BY" it. It's a benefit/limitation of SQL -- save time by giving random rows, or spend time sorting them. Something that you should be wary of though... If you do this: INSERT INTO table (id) values (1,2,3,4...10); Your select would be:

[sqlalchemy] Re: load_only doesn't affect joins

2015-12-03 Thread Jonathan Vanasco
Thanks for posting a full self-contained working example of your problem! -- 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 email to sqlalchemy+unsubscr...@googlegroups.com.

[sqlalchemy] Splitting a table ?

2015-12-02 Thread Jonathan Vanasco
I recently had to "split" or partition another table into 2 -- one of high write and low write access. The new table is just the high-write columns fkey'd onto the original table, and handled with a relationship. I was wondering if there was any "shortcut" in sqlalchemy to automatically

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

2015-12-01 Thread Jonathan Vanasco
On Tuesday, December 1, 2015 at 3:39:02 PM UTC-5, Chris Withers wrote: > > Indeed, but that's not quite what I asked ;-) > > I'm after setting the next value using, eg, setval: > > Ah, sorry. I saw "next value" and thought "nextval", not setval. The `Sequence` object just seems to support a

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

2015-12-01 Thread Jonathan Vanasco
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 earlier today and remembered it when seeing this post. -- You received this message because you are subscribed to

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

2015-12-01 Thread Jonathan Vanasco
On Tuesday, December 1, 2015 at 5:02:28 PM UTC-5, Chris Withers wrote: > > Does the .listen example there work or does it need the patch to land? > The ticket is still open, so the patch is probably needed (and looks to be Michael's first attempt at making something pass). -- You received

Re: [sqlalchemy] Re: postgresql, jsob and like operator

2015-12-01 Thread Jonathan Vanasco
On Tuesday, December 1, 2015 at 7:12:15 PM UTC-5, Michael Bayer wrote: see also the JSON operators which have some built-in text casting stuff: > > > http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html?highlight=json#sqlalchemy.dialects.postgresql.JSON > > > this is also getting

[sqlalchemy] Re: postgresql, jsob and like operator

2015-12-01 Thread Jonathan Vanasco
I don't think you can get that exact query staying within the ORM's cross-platform functionality -- I don't think there is anything that can generate the `::` version of casting... but I think something like this should produce the same output: r = session.query( Device.id, Device.name,

[sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-11-30 Thread Jonathan Vanasco
You should ask on the flask/flask-sqlalcemy support channel. They'll be better able to help. According to the docs : ~ Where can I get help? Join us on the #pocoo IRC channel on irc.freenode.net. According to their API docs and examples, setting __tablename__ (standard sqlalchemy

[sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-11-30 Thread Jonathan Vanasco
It should still work as a reference because the pacakge you use doesn't override this. The extension's API makes this clear: http://flask-sqlalchemy.pocoo.org/2.1/api/#models _tablename__ The name of the

Re: [sqlalchemy] Re: Quick way to deep copy an object?

2015-11-30 Thread Jonathan Vanasco
Look into `cascade` Here's a related thread https://groups.google.com/forum/#!searchin/sqlalchemy/cascade|sort:date/sqlalchemy/eIOkkXwJ-Ms/JLnpI2wJAAAJ -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop

[sqlalchemy] Re: set next value of postgres sequence

2015-11-28 Thread Jonathan Vanasco
There is a `Sequence` object that can be delcared like a table >From the docs: http://docs.sqlalchemy.org/en/latest/core/defaults.html#defining-sequences seq = Sequence('some_sequence')nextid = connection.execute(seq) -- You received this message because you are subscribed to the Google

[sqlalchemy] Re: Creating a derived class object without inserting into base class table

2015-11-27 Thread Jonathan Vanasco
On Wednesday, November 25, 2015 at 5:01:38 PM UTC-5, amit geron wrote: > In Flask-SQLAlchemy there are default table names, and in this case they > would be just 'User', 'A' and 'B', which are already unique. > flask-sqlachemy doesn't overrwrite this feature of SqlAlchemy. See this

Re: [sqlalchemy] Best way to use SERIALIZABLE READ ONLY DEFERRABLE transaction with the ORM?

2015-11-17 Thread Jonathan Vanasco
On Tuesday, November 17, 2015 at 9:14:51 AM UTC-5, Michael Bayer wrote: > > > conn = session.connection() > conn.detach() > conn.execute("set session isolation ") > > < work with connection> I use this strategy, but without `detatch`. I do this with SqlAlchemy in a webapp context, so I

[sqlalchemy] Re: N-Triples to MySQL

2015-11-03 Thread Jonathan Vanasco
You probably need to ask this on an rdflib forum. Looking at your code, you're just tossing a SqlAlchemy engine into rdflib. You probably need to integrate some sort of plugin, such as https://github.com/RDFLib/rdflib-sqlalchemy -- You received this message because you are subscribed to the

Re: [sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-11-03 Thread Jonathan Vanasco
Ah ha! I figured this out. It was a mix of a lazy eye and some peculiarities between Postgres(live) and sqlite(test-case). Given the query: session.query(Foo).options(contains_eager('bar')).order_by(Foo.id.desc()).offset(0).limit(100).all()] The SQL is (approx) select foo.*, bar.*

Re: [sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-10-30 Thread Jonathan Vanasco
On Friday, October 30, 2015 at 11:38:50 AM UTC-4, Michael Bayer wrote: > you wouldn't typically want to specify contains_eager('bar') if the SQL > has no JOIN in it, which you'd do with query.join(). There's no valid reason for using the `contains_eager` here -- it's just a typo. I

[sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-10-29 Thread Jonathan Vanasco
I've spent an hour trying to reproduce this bug and can't. I'm hoping someone can suggest what might be going on so I can make this reproducable for a bug report I have 2 classes: class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) bar_id

Re: [sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-10-29 Thread Jonathan Vanasco
On Thursday, October 29, 2015 at 7:33:47 PM UTC-4, Michael Bayer wrote: > > i dont have an immediate answer, though i wonder why you aren't using > ~Bar.is_x.is(True) for that "IS NOT"... > Old habits and styleguide. The `~` ended up being missed on too many glances and code-reviews. >

[sqlalchemy] Re: best way to query from a tuple of parameters

2015-10-27 Thread Jonathan Vanasco
Ah, sorry about that. I (almost) always nest "or_" in "and_". I don't think I've ever done the inverse! -- 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 email to

[sqlalchemy] Re: best way to query from a tuple of parameters

2015-10-26 Thread Jonathan Vanasco
Are you looking for the `or_` from sqlalchemy.sql import and_, or_ abcd = or_((table.col_1 == a, table.col_2 == b), (table.col_1 == b, table.col_2 == c), ) session.query(table).filter(**abcd).all() that should generate something like SELECT * FROM table WHERE (col_1 == a and col_2 ==

[sqlalchemy] Re: running parallel migrations using sharded/partioned/spaced queries?

2015-10-14 Thread Jonathan Vanasco
Crap. That's way simpler. Thanks! I could even use Postgres as the orchestrator -- just create a table of ids and loop through those based on migration status. (new table would avoid the re-write on a full record from Postgres). -- You received this message because you are subscribed to the

[sqlalchemy] running parallel migrations using sharded/partioned/spaced queries?

2015-10-14 Thread Jonathan Vanasco
I have to run a script on 2MM objects to update the database. Not really a schema migration, more like changing the internal data representation in the fields. There's a bit of post-processing and bottlenecks involved, so doing everything one-at-a-time will take a few days. I'd like to split

[sqlalchemy] emulating psql's "\copy" function?

2015-10-13 Thread Jonathan Vanasco
As part of an archiving routine that uses SqlAlchemy, I need to execute some pretty specific commands using `\copy` to archive a selection of columns, in a special order, into a csv. Doing some digging, psycopg2 provides an interface to `COPY` -- but that doesn't work for my needs. I'd

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

2015-10-08 Thread Jonathan Vanasco
I'll try to explain, hopefully this is the right answer. My guess is that you are seeing the identity as a tuple of primary keys and that can be confusing. If so, that's because 'orm.state.InstanceState.identity` just returns the primary key. SqlAlchemy actually tracks it the identity in a

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-30 Thread Jonathan Vanasco
On Tuesday, September 8, 2015 at 9:00:12 PM UTC-4, Michael Bayer wrote: > > q = select([tab.c[name] for name in ["id", "name", "address"]]) > adding... If you want to load particular columns off a relationship, you even do that using the `load_only` method. -- You received this message

[sqlalchemy] Re: Handle multiple relations between two rows/objects

2015-09-30 Thread Jonathan Vanasco
Most ORMs, SqlAlchemy included, require a primary key. This page in the documentation describes why: http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key -- You received this message because you are subscribed to the Google Groups

Re: [sqlalchemy] DB sync on application level

2015-09-27 Thread Jonathan Vanasco
I don't like this idea. but... You should familiarize yourself with two-phase commits. sqlalchemy supports this on mysql and postgresql. basically everyone votes to commit yay/nay in phase 1, then a commit is made (if unanimous yays) or rollback executed in phase 2. -- You received this

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

2015-09-25 Thread Jonathan Vanasco
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 flags on how to act. It's not pretty, but it

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-25 Thread Jonathan Vanasco
It looks like I imported the `sqlalchemy.alias` instead of `sqlalchemy.orm.aliased`, and just typod when posting here. switching to sqlalchemy.orm.aliased -- which I used in an identical manner 7 other times in this file -- immediately fixed things. thanks for setting me straight. looks like

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

2015-09-25 Thread Jonathan Vanasco
It's a code management style that we ended up on :( -- 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 email to sqlalchemy+unsubscr...@googlegroups.com. To post to this

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-24 Thread Jonathan Vanasco
On Thursday, September 24, 2015 at 3:05:56 AM UTC-4, David Allouche wrote: > That looks like the right approach. There is probably something else in > your actual code that is causing "it [to] not work". > > To get a better understanding of "it did not work", I would look at the >

[sqlalchemy] Re: Auto filter a relationship?

2015-09-24 Thread Jonathan Vanasco
I hit send early. That form should/will work for reading - i use it heavily. I'm not sure how/if it will interact with the collections management system (backref/backpopulates, etc). -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To

Re: [sqlalchemy] Re: Auto filter a relationship?

2015-09-24 Thread Jonathan Vanasco
Your use of association_proxy seems odd to me. That plugin is normally used to "cut out" the middleman when using a join with an association pattern and avoid a hop/remount a relationship from one object onto another. With my understanding and use of that plugin, you're basically setting the

[sqlalchemy] Re: Auto filter a relationship?

2015-09-24 Thread Jonathan Vanasco
packages = sa.orm.relationship("Package", primaryjoin="and_(ReservationPackage.package_id==Package.id, Package.deleted IS NOT NULL)") -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails

[sqlalchemy] how to dynamically work with an aliased table?

2015-09-23 Thread Jonathan Vanasco
I have a query where I derive an object based on some dynamic filters on a relationship: sql_ors = [ sqlalchemy.func.lower(Bar.string_id) == id_search.lower(), sqlalchemy.func.lower(Bar.numeric_id) == id_search.lower(), ] query = dbSession.query(Foo)\

[sqlalchemy] Re: How to get specific attribute from last row?

2015-09-23 Thread Jonathan Vanasco
You should share your SqlAlchemy model along with an executable script that illustrates the query and others can comment-on or fix. You are simply showing a mixture of raw data and random results that are without any context. -- You received this message because you are subscribed to the

[sqlalchemy] has anyone used/abused events to reflect db changes on cached orm objects?

2015-09-22 Thread Jonathan Vanasco
This is, admittedly, an abuse of SqlAlchemy. I'm wondering if anyone else has dealt with this situation before and how they handled it. We have a handful of situations where SqlAlchemy generates a raw sql update against a table. Something like _table = model.Foo.__table__

Re: [sqlalchemy] has anyone used/abused events to reflect db changes on cached orm objects?

2015-09-22 Thread Jonathan Vanasco
What haven't you thought of, Michael Bayer? Is there anything SqlAlchemy can't do?!?!? -- 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 email to

[sqlalchemy] Re: Mixed data type for a column

2015-09-18 Thread Jonathan Vanasco
If I understand you correctly, I would just do this: 1. Use 3 different columns for the value -- each a native data type. 2. Use `coalesce` to handle sorting 3. When displaying in sqlalchemy, just use a property to proxy displaying the set column (and explicitly work with the correct columns

[sqlalchemy] Re: expire_on_commit and relationships

2015-09-17 Thread Jonathan Vanasco
Immediately I notice that the attributes `father`/`mother` have no relationship to the `Parent` object. I think specifying backref/back_populates should solve your issue: http://docs.sqlalchemy.org/en/rel_1_0/orm/backref.html Also, FYI You can use `expire` on just the relationships

[sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Jonathan Vanasco
I'm about to migrate about 70 relationships from backref to back_populates so the model reads cleaner/better documented.. Most are straightwordard, but a handful are more complex -- order_by or uselist are on the backref, or there may be a handful of args or primaryjoin on the relationship.

Re: [sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Jonathan Vanasco
On Wednesday, September 16, 2015 at 4:14:35 PM UTC-4, Michael Bayer wrote: > > maybe you can run through all the mappings with a script and produce a > textfile indicating the settings for all the relationships. then you can > verify that the back_populates code change produces the same

[sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Jonathan Vanasco
given the object `source`, these both work cols = [c.key for c in list(source.__table__.columns)] cols = [c.name for c in sqlalchemy.orm.class_mapper(source.__class__).mapped_table.c] I'm sure there are other ways. is there an ideal / canonical way of getting this data?

Re: [sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Jonathan Vanasco
Thanks. For this bit of code, I just need the column names. We ran into an edge-case during some new tests where instead of having one of a read-through cache object (a dogpile managed dict!) a hot SqlAlchemy object got used. This bit of code just cleans up and reformats some column data

[sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Jonathan Vanasco
This drove me crazy for an hour today, until I finally figured out what was going on. I have a class with a few relationships: class Foo(base): # relationships have a prefix that describe the relation l_ (list) or o_ (scalar) l_Bars = relationship("Bars")

Re: [sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Jonathan Vanasco
On Wednesday, September 16, 2015 at 6:56:20 PM UTC-4, Michael Bayer wrote: > > OK, what's great here is (in keeping with bugs are always reported in > twos, no matter how long theyve been around) that someone just hit this > yesterday: > Ha! I missed reading that one! this should

Re: [sqlalchemy] What about bit fields / bit masks?

2015-08-31 Thread Jonathan Vanasco
postgres wise: I use an INT field to store bitwise data. I wrote a class that declares enumerated sets and manages the the bitwise operations, then serializes it to an int. I use an @property to deserialize reads and manually serialize the writes (not enough time/need to integrate with

Re: [sqlalchemy] Is it possible to set the constraint unique = True except for empty string into SQLAlchemy?

2015-08-24 Thread Jonathan Vanasco
If you're using Postgres, you actually wouldn't even need to use a partial index if you can save NULL values instead of empty strings -- a unique constraint would work as intended because Postgres does not compare NULL values to one another. -- You received this message because you are

Re: [sqlalchemy] Does twophase=True limit to only two databases at the same time?

2015-08-14 Thread Jonathan Vanasco
twophase deals with the transaction commit protocol , and is unlreated to anything else in your example. (http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session.params.twophase) You'd simply create an engine3 and bind whatever object classes to it. FWIW.

[sqlalchemy] Re: Does twophase=True limit to only two databases at the same time?

2015-08-14 Thread Jonathan Vanasco
On Friday, August 14, 2015 at 5:16:48 PM UTC-4, Jinghui Niu wrote: If I still want to use SQLite, and I still need to do vertical partition, what can I do? Am I out of luck? You can, but not with a two-phase commit. Two-phase commit basically works like this: - round 1, everyone

[sqlalchemy] Re: Does twophase=True limit to only two databases at the same time?

2015-08-14 Thread Jonathan Vanasco
Well, this problem doesn't really have anything to do with SqlAlchemy -- you should probably ask people for advice on the Sqlite lists or Stack Overflow. You can segment out your database into 3 files using the example above. You will just run into an issue where -- because there isn't a

Re: [sqlalchemy] advice sought - handling a relationship cascade

2015-08-06 Thread Jonathan Vanasco
On Wednesday, August 5, 2015 at 10:08:35 PM UTC-4, Michael Bayer wrote: viewonly=True? That was the EXACTLY what I needed. Thank you! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails

[sqlalchemy] advice sought - handling a relationship cascade

2015-08-05 Thread Jonathan Vanasco
I have 2 related classes • ProvisionedAccess (auth policy) • Credentials (public/private key) ProvisionedAccess has 2 relationships: • keyset_active -- the active keyset, identified by having an is_active flag • keys_all -- all historical keys I've implemented them as below.

Re: [sqlalchemy] Why is there no SQLA-List class?

2015-08-04 Thread Jonathan Vanasco
On Tuesday, August 4, 2015 at 11:24:06 AM UTC-4, Michael Bayer wrote: it's a recipe. Please tailor it to your needs. Michael's recipe is rather advantageous though. This encodes a `null` JSON string into a Python None, which corresponds to a NULL database field. Encoding as the

[sqlalchemy] Re: Bizzarre insert behavior: NULL constraint violation with non-null value, column changes every run.

2015-07-28 Thread Jonathan Vanasco
Have you tried toggling the sqlalchemy connection string? http://docs.sqlalchemy.org/en/rel_1_0/core/engines.html#sqlalchemy.create_engine.params.case_sensitive -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and

[sqlalchemy] Re: Bizzarre insert behavior: NULL constraint violation with non-null value, column changes every run.

2015-07-28 Thread Jonathan Vanasco
Also, check this: http://docs.sqlalchemy.org/en/rel_1_0/dialects/oracle.html#identifier-casing -- 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 email to

Re: [sqlalchemy] Bizzarre insert behavior: NULL constraint violation with non-null value, column changes every run.

2015-07-28 Thread Jonathan Vanasco
Glad it worked out! Sorry my suggestions didn't pan out -- 90% of oracle issues i've had have come down to some default case setting in a file I didn't know about. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group

Re: [sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Jonathan Vanasco
On Friday, July 24, 2015 at 1:20:15 PM UTC-4, Richard Kuesters wrote: well, as a general non-specific view yes, it can be another approach. but, for the piece of code that drove me to this question, i really need to use after_flush :) Well I mean... you could use that pattern to catch

[sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Jonathan Vanasco
Couldn't you handle much of this with the Descriptors/Hybrids pattern? http://docs.sqlalchemy.org/en/latest/orm/mapped_attributes.html#using-descriptors-and-hybrids -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and

[sqlalchemy] Re: performance of SA

2015-07-24 Thread Jonathan Vanasco
Are you comparing the speed of SqlAlchemy Core operations or SqlAlchemy ORM operations? The ORM is considerably slower. The core engine is much faster. There is also this: http://docs.sqlalchemy.org/en/latest/faq/performance.html -- You received this message because you are subscribed to

Re: [sqlalchemy] Syntax Checking

2015-07-24 Thread Jonathan Vanasco
flake8 is super simple - it checks your code for mistakes (undeclared vars, non-runnable code, etc) and pushes you to write pep8 style code. the only things you need to do really are: * write a .cfg for various projects, so you can turn off some warnings * get in the habit of running it before

Re: [sqlalchemy] Syntax Checking

2015-07-24 Thread Jonathan Vanasco
In terms of linters, `flake8` (https://pypi.python.org/pypi/flake8) catches most mistakes I've made with SqlAlchemy. It's also useful to start writing Unit Tests that will interact with your SqlAlchemy models in predicted ways -- in addition to continually checking core functionality. -- You

Re: [sqlalchemy] Re: set vs after_flush events

2015-07-24 Thread Jonathan Vanasco
On Friday, July 24, 2015 at 2:06:15 PM UTC-4, Richard Kuesters wrote: well, application-wise it is really to run other procedures, not from the database or python side, but from a message broker that's expecting anything to happen to that value -- even if it's just a touch :) err ...

Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-23 Thread Jonathan Vanasco
So my code above is just completely wrong. This code actually does what one expects: def recursive_expunge(obj, dbSession): def _recursive_expunge(_obj): _instance_state = sqlalchemy.inspection.inspect(_obj) _mapper = _instance_state.mapper try:

Re: [sqlalchemy] question about `sqlalchemy.orm.mapper.Mapper` and objects

2015-07-23 Thread Jonathan Vanasco
Yeah, no error. I'll guess that: * My code isn't doing what I intended * but *SqlAlchemy isn't raising an error So I can work with that. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails

[sqlalchemy] question about `sqlalchemy.orm.mapper.Mapper` and objects

2015-07-23 Thread Jonathan Vanasco
This is an extension of my question about recursive object expunging (https://groups.google.com/forum/#!topic/sqlalchemy/lUhCDfkPc9k) Is the mapper that is accessed via `sqlalchemy.inspection.inspect(obj).mapper` and stored in `object.__mapper__` specific to the instance? I thought it was the

Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco
On Friday, July 17, 2015 at 2:46:42 PM UTC-4, Michael Bayer wrote: well then yeah you need to do your own thing :) i foolishly thought this was something others may have experienced ;) i'd use inspect(obj) to get the mapper.but also you might want to use cascade_iterator:

[sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco
I'm updating our visual preview tool for edits, and ran into an issue. In order to best mimic the production view, I can't simply clone the objects any longer (they have way too many attributes and relationships) and must apply edits onto the real object. I'd like to ensure that changes

Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco
editing the cascade isn't an option. for now this seems to work, though it's ugly. def recursive_expunge(obj, dbSession): def _recursive_expunge(_obj): if hasattr(_obj, '__mapper__'): for rel in obj.__mapper__.relationships:

[sqlalchemy] Re: How to jsonify Query result?

2015-07-13 Thread Jonathan Vanasco
The tuples are a variant of python's NamedTuple (sqlalchemy.utils._collections.KeyedTuple) and contain the column names in a `keys` method. You can just write a json adapter that handles instances of KeyedTuple and iterates over their K/V pairs. -- You received this message because you are

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Jonathan Vanasco
you probably need to modify the various objections with a `.select()` or `.subquery()` e.g: query_select = query.select() q = intersect.join(query_select, query_select.c.sid, intersect.c.sid) pay attention to the docs on what the various methods return. some return a selectable, others

[sqlalchemy] extreme/aggressive query simplification with load_only

2015-07-02 Thread Jonathan Vanasco
wondering- has anyone tried ways to mimic the load_only feature but not fetch the primary key (which is autoloaded, even if not specified)? I know that the orm needs this to make load-only work as intended, which is why I used the work 'mimic'. trying to get some data-transfer down, and some

[sqlalchemy] Re: sqlaclhemy ORM don't update jsonb[postgres-psycopg2]

2015-06-30 Thread Jonathan Vanasco
This sounds like you may be having issues with mutation tracking on edits. http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html?highlight=jsonb#sqlalchemy.dialects.postgresql.JSONB The JSON

[sqlalchemy] Re: how to recycle connections grown stale after checkout

2015-06-29 Thread Jonathan Vanasco
http://docs.sqlalchemy.org/en/latest/core/pooling.html#dealing-with-disconnects -- 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 email to

[sqlalchemy] Re: SQLAlchemy 1.0.6 Released

2015-06-25 Thread Jonathan Vanasco
Michael, I had no idea about this versioning. Looking it up, I first found this in the docs: http://docs.sqlalchemy.org/en/latest/orm/examples.html#versioning-objects That didn't look right, so I checked the changelogs and saw some specifics in the 09 release note. Looking up those terms, I

Re: [sqlalchemy] Re: SQLAlchemy 1.0.6 Released

2015-06-25 Thread Jonathan Vanasco
I guess they are related. I was just thinking about a link on each page that says For another type of versioning within SqlAlchemy, click here. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving

Re: [sqlalchemy] Query hangs after a while

2015-06-13 Thread Jonathan Vanasco
Are you positive there isn't some transactional locking going on? What does mysql say about locked tables/rows when things are stalled? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from

[sqlalchemy] Re: What is the SQLAlchemy terminology for ..?

2015-06-11 Thread Jonathan Vanasco
Your question and example are both a bit confusing. I'll try to impart some knowledge that can help you re-focus an ask. 1. In your example, `Session.query(CaseTestInstance)` will return all the data in the `cases_test_instance` table. 2. Recursive Queries can mean a few things (and is often

[sqlalchemy] Re: .any() queries and MySQL performance

2015-06-11 Thread Jonathan Vanasco
FWIW, the first thing I noticed is that this will rarely work well, as the index is on a 255length column. if your table is big, you would definitely see a large improvement by storing a 32char md5 version of that column, creating a partial index on the first 5-8 characters, and then adding a

[sqlalchemy] Re: Session is commiting without an add()

2015-06-10 Thread Jonathan Vanasco
You're experiencing exactly what Michael pointed you to. Person has a relationship+backref to SourceDatabase though `Person.source_database`. When you create a `John` and assign the existing source_database, sqlalchemy is implicitly adding the Person so that the update you explicitly

[sqlalchemy] Re: How to find out if an object is a SQLAlchemy mapped one?

2015-06-05 Thread Jonathan Vanasco
You should be able to handle this by inspecting the object. http://docs.sqlalchemy.org/en/latest/core/inspection.html It will raise `sqlalchemy.exc.NoInspectionAvailable` if you can't inspect. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] Re: ...and MVC

2015-06-01 Thread Jonathan Vanasco
On Sunday, May 31, 2015 at 4:48:09 AM UTC-4, Fayaz Yusuf Khan wrote: I do the former in cases which involve very long transactions. (Batch uploads and processing. I'm counting batch and background tasks as part of the controller layer here.) I manage transactions manually in the

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Jonathan Vanasco
All my models inherit from an additional base class with this method: def columns_as_dict(self): return a dict of the columns; does not handle relationships return dict((col.name, getattr(self, col.name)) for col in sqlalchemy_orm.class_mapper(self.__class__).mapped_table.c)

Re: [sqlalchemy] Session.close() implicite

2015-05-26 Thread Jonathan Vanasco
Michael- FYI, memoized_property isn't documented. it looks to be in the active source, and there is a recipe for a roll-your-own memoized orm properties. On Monday, May 25, 2015 at 11:43:58 AM UTC-4, c.b...@posteo.jp wrote: I am quite new to Python and not familiar with the decorator

[sqlalchemy] Re: ...and MVC

2015-05-26 Thread Jonathan Vanasco
In most implementations, the answer would be: None of the above. Many MVC style frameworks (including all the near variants) will place the SqlAlchemy session management in a WSGI middleware layer or a tween. Usually it will look like (pseudocode): try:

[sqlalchemy] Re: restrict child count?

2015-05-19 Thread Jonathan Vanasco
I think I might understand you... You have a BOX, which could be a variable amount of sizes, and each size can hold a variable amount of items. You want to create a rule(s) that will ensure you do not have too many things in each box. If that is that case: 1. You could use Triggers in

Re: [sqlalchemy] flake8 tips?

2015-05-18 Thread Jonathan Vanasco
I just found a bug in my code that is related to this, and wanted to circle back... I keep forgetting that these are not the same comparison on Postgres: Foo != True Foo IS NOT True They match as follows: `!= True` = [False, ] `IS NOT True` = [False, NULL] -- You received

[sqlalchemy] Re: Authoring Dialects: How to Fix AssertionError: assert Decimal('15.7563') in [15.7563] ?

2015-05-14 Thread Jonathan Vanasco
Can you share the test and any relevant code (ie, anything in the dialect that deals with this)? -- 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 email to

Re: [sqlalchemy] python customer function

2015-05-08 Thread Jonathan Vanasco
Would you be able to use a TypeDecorator? http://docs.sqlalchemy.org/en/latest/core/custom_types.html#sqlalchemy.types.TypeDecorator That will allow you to define a function for handling how sqlalchemy inserts and accesses the data from sql. -- You received this message because you are

[sqlalchemy] Re: contains_eager limited by .first()?

2015-05-08 Thread Jonathan Vanasco
The problem is a behavioral quirk. I'm not sure if this is a regression or not, but I've seen it brought up recently... IIRC: The join creates a matrix result (many rows), but `first()` only pulls the first item from the result. Calling 'one()' will pull all the results, but raise an error

<    1   2   3   4   5   6   7   8   9   10   >