Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-22 Thread 'Tony Cosentini' via sqlalchemy
do_orm_execute() (and freezing the results) totally allows for what I'm trying to do! Also I forgot to mention earlier, but this is only going to run in tests. Thanks again for all the help, Tony On Friday, October 20, 2023 at 11:10:23 PM UTC+8 Mike Bayer wrote: > > > On Fri, Oct

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread 'Tony Cosentini' via sqlalchemy
to automate finding these cases in order to add explicit flush calls when needed or just pass in the pending object instead of running a query. Tony On Fri, Oct 20, 2023 at 10:42 PM Mike Bayer < mike_not_on_goo...@zzzcomputing.com> wrote: > > > On Fri, Oct 20, 2023, at 9:50 AM,

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread 'Tony Cosentini' via sqlalchemy
goo...@zzzcomputing.com> wrote: > > > On Fri, Oct 20, 2023, at 8:08 AM, 'Tony Cosentini' via sqlalchemy wrote: > > Hi, > > Is there any way to listen for an event for when a query result gets > merged into a pre-existing object in the session? > > > this is the refresh even

[sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread 'Tony Cosentini' via sqlalchemy
in with the existing objects in the session. Thanks, Tony -- 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

Re: [sqlalchemy] DRYing up model relationships with custom properties

2023-05-03 Thread 'Tony Cosentini' via sqlalchemy
per so that you can apply > things after the fact, a good event for this would be "instrument_class": > https://docs.sqlalchemy.org/en/20/orm/events.html#sqlalchemy.orm.MapperEvents.instrument_class > > > On Wed, May 3, 2023, at 4:18 AM, 'Tony Cosentini' via sqlalchemy wr

[sqlalchemy] DRYing up model relationships with custom properties

2023-05-03 Thread 'Tony Cosentini' via sqlalchemy
on if it's possible to combine this into some kind of reusable utility to DRY it up? I'm not sure how important it is, but I'm still on 1.4.x, haven't made the jump to 2.x yet. Thanks! Tony -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

Re: [sqlalchemy] Re: load_only when loading relatinoships from an instance

2023-01-05 Thread 'Tony Cosentini' via sqlalchemy
populate_existing doesn't change the behavior, but expunge_all does. The code works correctly now though - it's just our test setup/teardown that was causing trouble (although it does seem like weird behavior). Thanks again for so much help with such a great library, Tony On Thursday, January

[sqlalchemy] Re: load_only when loading relatinoships from an instance

2023-01-04 Thread 'Tony Cosentini' via sqlalchemy
bizarre, but that gist link contains a really short sample that reproduces the same behavior. I'm running 1.4.44. Tony On Thursday, January 5, 2023 at 11:09:40 AM UTC+8 Tony Cosentini wrote: > Funny enough, this is what I tried. I just wrote up a small sample script > using defau

[sqlalchemy] Re: load_only when loading relatinoships from an instance

2023-01-04 Thread 'Tony Cosentini' via sqlalchemy
gt;> >> I can do this if I just query for model_b via the foreign key instead of >> using the relationship property, but I'd like to avoid that if possible. >> >> Sorry if this question is a bit weird/confusing, it's kind of a strange >> use case. >> >> Thanks,

[sqlalchemy] load_only when loading relatinoships from an instance

2023-01-04 Thread 'Tony Cosentini' via sqlalchemy
the future, only specific columns are loaded in at first. I can do this if I just query for model_b via the foreign key instead of using the relationship property, but I'd like to avoid that if possible. Sorry if this question is a bit weird/confusing, it's kind of a strange use case. Th

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2023-01-04 Thread 'Tony Cosentini' via sqlalchemy
for helping look into this, Tony On Monday, November 14, 2022 at 3:43:53 PM UTC+8 Tony Cosentini wrote: > Oh wow, this sounds like it would definitely impact us. I'm out this week > travelling, but I will definitely upgrade + re-enable the cache and report > back. > > Thanks! >

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-11-13 Thread 'Tony Cosentini' via sqlalchemy
lchemy/sqlalchemy/issues/8790. > > On Thu, Nov 3, 2022, at 8:33 AM, Mike Bayer wrote: > > > > On Thu, Nov 3, 2022, at 3:11 AM, 'Tony Cosentini' via sqlalchemy wrote: > > Hey, sorry for the crazy delay on this! > > We ended up turning off the cache in everything via que

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-11-03 Thread 'Tony Cosentini' via sqlalchemy
that runs into these kinds of issues. Thanks again Mike for the helpful response! Tony On Friday, October 21, 2022 at 8:08:32 PM UTC+8 Tony Cosentini wrote: > Hi Mike, > > Thanks for such a fast reply! We tried setting query_cache_size on a > canary environment today, will be ro

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-10-21 Thread 'Tony Cosentini' via sqlalchemy
of a theory though). I'll report back if we see any changes. Thanks again for the fast reply (and for building such a useful + well documented library), Tony On Friday, October 21, 2022 at 12:20:07 PM UTC+8 Mike Bayer wrote: > > > On Fri, Oct 21, 2022, at 12:00 AM, 'Tony Cosen

[sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-10-20 Thread 'Tony Cosentini' via sqlalchemy
in more, but just asking in case there is something obvious, Tony -- 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

Re: [sqlalchemy] Ocassional Gevent BlockingSwitchOutError crashes when using pool_recycle

2020-06-04 Thread Tony Cosentini
Hey Mike, You were totally correct! We are migrating to a new engine (via an env var flag) and I totally forgot to wire up a call to remove() after handling requests with the new session. Thanks so much for suggestions! It made debugging this much easier. Tony On Wednesday, June 3, 2020

[sqlalchemy] Ocassional Gevent BlockingSwitchOutError crashes when using pool_recycle

2020-06-02 Thread Tony Cosentini
ode and everything looks correct - it's happening before anything else and I confirmed that the modules are all patched. Additionally, we have some other processes that run without gevent and they don't seem to have any issue with pool_recycle (although they don't have throughput like this

[sqlalchemy] Warning about using backref with viewonly - how to make a two-way read-only relation?

2020-03-18 Thread Tony Hignett
Hi, I'm trying to upgrade from 1.2.2 to 1.3.15 and a number of our relations have started generating these warnings: ``` SAWarning: Setting backref / back_populates on relationship to refer to viewonly relationship will be deprecated in SQLAlchemy 1.4, and will be disallowed in a future

Re: [sqlalchemy] Conditional onupdate

2019-05-22 Thread Tony Cao
of these ended up working. Do you know if there's a way to specify an onupdate function to return a SQL column? On Thursday, May 16, 2019 at 2:49:56 PM UTC-7, Mike Bayer wrote: > > On Thu, May 16, 2019 at 4:26 PM Tony Cao > wrote: > > > > Ohh I see thanks for the help!

Re: [sqlalchemy] Conditional onupdate

2019-05-16 Thread Tony Cao
On Wed, May 15, 2019 at 6:10 PM Tony Cao > wrote: > > > > I mean query.update(). > > > > Ah our goal was to make it so the update in question happened > automatically without the developer having to explicitly specify it - in > that case both obj.attr = x

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Tony Cao
ALUES clause, so you know from your own > data what the UPDATE statement will be. > > > > On Wed, May 15, 2019 at 4:14 PM Tony Cao > wrote: > > > > Ah but it also looks like the before_update event isn't triggered when > doing bulk query updates, whic

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Tony Cao
spect(obj).attrs['some_attr'].history > > > https://docs.sqlalchemy.org/en/13/orm/internals.html#sqlalchemy.orm.state.AttributeState > > > > On Wed, May 15, 2019 at 1:14 PM Tony Cao > wrote: > > > > Hi, > > > > Thanks for the response! I also tried

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Tony Cao
-a-db-update) that suggests looking at the history of the attribute state - is there a better way? On Wednesday, May 15, 2019 at 7:55:44 AM UTC-7, Mike Bayer wrote: > > On Mon, May 13, 2019 at 4:18 PM Tony Cao > wrote: > > > > Hi all, > > > > Is there way to

[sqlalchemy] Conditional onupdate

2019-05-13 Thread Tony Cao
Hi all, Is there way to use Column.onupdate conditionally? For example, say I have: class A(Base): foo = Column(String) bar = Column(String) foo_updated = Column(DateTime, onupdate=update_fn) # Should only update when foo is updated def update_fn(context): if ...: # How can I

Re: [sqlalchemy] pg8000 driver and JSON test

2018-06-07 Thread Tony Locke
) return process The problem is that now type_coerce returns a pg8000.PGJson type, rather than a serialized JSON string, causing the test_crit_against_string_coerce_type test to fail. I wonder if there's a different approach that I should be taking? Thanks, Tony. On 6 June 2018 at 14:56

[sqlalchemy] pg8000 driver and JSON test

2018-06-06 Thread Tony Locke
ix in the driver to make it work, so any help is greatly appreciated. Thanks, Tony. -- 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://stac

[sqlalchemy] SQL Alchemy versus psycopg2

2018-05-01 Thread Tony S
, and so on? TIA Tony -- 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. --- You received

Re: [sqlalchemy] Updating pg8000 dialect following new release of pg8000

2017-09-05 Thread Tony Locke
On Friday, 1 September 2017 17:40:23 UTC+1, Mike Bayer wrote: > > On Fri, Sep 1, 2017 at 12:09 PM, Tony Locke <tlo...@tlocke.org.uk > > wrote: > > No I don't think it's a bug because pg8000 is designed to always create > a > > prepared statement if one

Re: [sqlalchemy] Updating pg8000 dialect following new release of pg8000

2017-09-01 Thread Tony Locke
) which, if exceeded, triggers the closing of all prepared statements. So memory use never goes off to infinity. On 1 Sep 2017 4:54 p.m., "Mike Bayer" <mike...@zzzcomputing.com> wrote: > On Fri, Sep 1, 2017 at 10:57 AM, Tony Locke <tlo...@tlocke.org.uk> wrote: >

Re: [sqlalchemy] Updating pg8000 dialect following new release of pg8000

2017-09-01 Thread Tony Locke
('postgresql+pg8000', 'prepared statements use memory'), and now all the test test/aaa_profiling/test_memusage.py tests pass. Now, on with the other tests! On Thursday, 31 August 2017 15:15:16 UTC+1, Mike Bayer wrote: > > On Thu, Aug 31, 2017 at 7:02 AM, Tony Locke <tlo...@tlocke.org.uk

[sqlalchemy] Updating pg8000 dialect following new release of pg8000

2017-08-31 Thread Tony Locke
There's a new release (1.11.0) of the pg8000 driver for PostgreSQL. It's a pure-python driver, and it already has a dialect for SQLAlchemy. This latest release is not backwardly compatible with the previous release, and I'm trying to modify the dialect accordingly. The main change is that

Re: [sqlalchemy] The right way to use gevent with sqlalchemy

2017-07-17 Thread Tony Wang
gt; - we don't commit() the session in the same place that we are doing > individual insert(), delete(), select() statements - we should have a > single transaction surrounding a group of operations. > > "Make sure you have a clear notion of where transactions begin and > end

Re: [sqlalchemy] The right way to use gevent with sqlalchemy

2017-07-15 Thread Tony Wang
nd session? It doesn't work. If not, could you share me some demo code? Thanks! On Sat, Jul 15, 2017 at 11:51 PM Mike Bayer <mike...@zzzcomputing.com> wrote: > On Fri, Jul 14, 2017 at 8:08 PM, Tony Wang <plantpark@gmail.com> > wrote: > > I simplify a complex system of g

[sqlalchemy] The right way to use gevent with sqlalchemy

2017-07-14 Thread Tony Wang
I simplify a complex system of gevent with sqlachemy to a simple demo code . Before using of sqlachemy, pymysql is my best choice for communication between MySql and gevent because of its easy and direct usage. But now I

[sqlalchemy] What is the terminology for ...?

2015-06-11 Thread Tony C
Hi I'm new to databases, SQL, and SQLAlchemy. I've been going through the tutorials and docs at SQLAlchemy.org trying to find a solution to what I believe is a very simple issue with database quiries, however I'm quite uncertain of the terminology. I'm using the declarative form of SQL

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

2015-06-11 Thread Tony C
the class definition, the output does not change at all. I don't understand this. Thanks Tony -- 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

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

2015-06-11 Thread Tony C
Thanks Jonathan, Your question and example are both a bit confusing Yes-as I mentioned in my post, and I am new to databases and SQL,so I don't know how to ask for what I'm looking for. After creating the relationship that you mentioned, my queries now pull the data from the referenced tables.

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

2015-06-11 Thread Tony C
Thanks David On Thursday, June 11, 2015 at 11:53:44 AM UTC-7, David Allouche wrote: On 11 Jun 2015, at 19:09, Tony C capp...@gmail.com javascript: wrote: I'm new to databases, SQL, and SQLAlchemy. I've been going through the tutorials and docs at SQLAlchemy.org trying to find a solution

Re: [sqlalchemy] Test test/engine/test_pool.py::QueuePoolTest::()::test_queuepool_close fails

2015-04-15 Thread Tony Locke
on. 44a9820b4e02f65b3884fa2c016efc has a fix which adds explicit cleanup to a few connection objects that are checked out and not closed, leading to the pool._refs collection to not be empty when that particular test starts. This is backported to 0.9 as well. On 4/7/15 3:22 PM, Tony

[sqlalchemy] Test test/engine/test_pool.py::QueuePoolTest::()::test_queuepool_close fails

2015-04-07 Thread Tony Locke
/test_pool.py::QueuePoolTest I'm sure I'm doing something really obviously wrong, but I'm not sure what, so I'd be grateful if anyone can help. Btw, it was the only test that failed when I ran the entire suite. Thanks, Tony. -- You received this message because you are subscribed to the Google

[sqlalchemy] Tests hang at test_ora8_flags

2015-03-19 Thread Tony Locke
cd076470baf2fce0eebf5853e3145d96a9d48378) One really odd thing is that if I run py.test with the -s option (don't capture output) then it runs fine. Also, if I run just test/dialect/test_oracle.py then it runs okay, it's only a problem when running all tests. Any ideas gratefully received! Thanks, Tony. -- You received

Re: [sqlalchemy] Create database with sqlalchemy 0.8.0 and postgres

2014-05-14 Thread Tony Locke
I've had a look at this and submitted a patch that should make autocommit work for the pg8000 Sqlalchemy dialect in the same way as it does for the psycopg2 dialect https://github.com/zzzeek/sqlalchemy/pull/88. On Friday, 9 May 2014 17:50:43 UTC+1, Tony Locke wrote: Hi, the pg8000 driver has

Re: [sqlalchemy] Create database with sqlalchemy 0.8.0 and postgres

2014-05-09 Thread Tony Locke
= Falsecursor.close()conn.close() I'm not sure if the SQLAlchemy driver for pg8000 supports using: conn.execution_options(“AUTOCOMMIT”) I'll investigate... Cheers, Tony. On Wednesday, 7 May 2014 01:08:00 UTC+1, Michael Bayer wrote: On May 6, 2014, at 6:09 PM, Michael Costello michael7

Re: [sqlalchemy] How form a many-to-many relationship with a 3-way association?

2014-04-03 Thread Tony B
Thank you very much! That was the nudge I needed. I saw association proxies in the docs, but wasn't sure that was what I wanted. It was! I had considered making the credits table an object, but wasn't sure it was the correct way. By doing that, in combo with an accessor property on Credit

[sqlalchemy] Re: How form a many-to-many relationship with a 3-way association?

2014-04-02 Thread Tony B
Cut and paste error. Here is the correct SQL from above. select documents.id, persons.name as person, roles.name as role from documents inner join credits on credits.document_id=documents.id inner join persons on credits.person_id=persons.id inner join roles on

[sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
/python-sqlalchemy-dynamic-order-by Thanks in advance. -Tony -- 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

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
. On Thu, Feb 13, 2014 at 7:08 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 13, 2014, at 6:21 PM, Tony Garcia tnyr...@gmail.com wrote: Hello, I'm new to SQLAlchemy and have searched high and low for a solution to my problem so I'm hoping someone here can help. I have a query where I

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Oops -- disregard the [start:end] at the end of the query and replace that with .all() On Thu, Feb 13, 2014 at 7:50 PM, Tony Garcia tnyr...@gmail.com wrote: Hmm.. I see what you're saying, but the column can be from any of the tables queried from, not just the Study table. So it could

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Actually, now I see that your suggestion would get me the column object (not a string), but it would still restrict me to the study table. On Thu, Feb 13, 2014 at 7:53 PM, Tony Garcia tnyr...@gmail.com wrote: Oops -- disregard the [start:end] at the end of the query and replace that with .all

Re: [sqlalchemy] Dynamic order by clause

2014-02-13 Thread Tony Garcia
Gotcha. Thanks Michael. Once I get the code working I'll post it here. Off to bed now, though. Cheers, Tony On Thursday, February 13, 2014 8:49:14 PM UTC-5, Michael Bayer wrote: everything in python is ultimately in a namespace, the names are strings, the values are the objects. like

Re: [sqlalchemy] Prepared Statements in Postgresql

2014-02-12 Thread Tony Locke
Hi, just to confirm, the executemany() method in pg8000 does use prepared statements. Cheers, Tony. On Friday, 15 January 2010 17:16:09 UTC, Michael Bayer wrote: mozillalives wrote: Hello Everyone, I am new to both sqlalchemy and elixir, but I have been using them for the past couple

Re: [sqlalchemy] How-to : update A also create an update of B

2012-08-31 Thread Tony Moutaux
Le jeudi 30 août 2012 17:16:40 UTC+2, Michael Bayer a écrit : def after_flush(session, flush_context): my_bs = figure_out_bs(session) new_session = Session(bind=session.connection()) new_session.add_all(my_bs) # this won't actually

[sqlalchemy] How-to : update A also create an update of B

2012-08-30 Thread Tony Moutaux
Hi there ! I'm going mad looking for a solution for what seems a simple problem. When object A is updated, I also want object B to be updated, using some computation based on A new values. From now, I can detect when A is modified using after_update. What I try is to look at event

[sqlalchemy] Re: How-to : update A also create an update of B

2012-08-30 Thread Tony Moutaux
A friend point me out the hybrid_property and the fact I can detect an update of A fields before doing the commit, issuing some update for B. I'll try this idea. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web

Re: [sqlalchemy] How-to : update A also create an update of B

2012-08-30 Thread Tony Moutaux
Only if some computation based on A new values means that there are SQL-level functions which you need to get at, does the rationale for after_update/after_flush events to come up.Unfortunately you can't emit a flush() within any of these events, as they are already local to the

[sqlalchemy] sorting a list of tables from a database based on their dependency order

2011-07-11 Thread Tony
: for foreign_key in table.foreign_keys: if foreign_key.target_fullname.split(.)[0] in sorted_table: pass else:break else: sorted_table.append(table_name) Thanks Regards Tony -- You received

Re: [sqlalchemy] [0.7.1] Building C extentions fail on installing for OS X

2011-06-24 Thread Tony Theodore
extensions either, but you seem to be using the Apple supplied version of Python. Try using either the python.org or macports versions - you'll generally have less problems with those. Cheers, Tony -- You received this message because you are subscribed to the Google Groups sqlalchemy group

[sqlalchemy] Re: Table name without quoting with upper case

2010-11-26 Thread Tony Moutaux
the quote attribut of the Table class in the SA doc, try it and it's all good. Now I just have to put it in the right place in my pylons files (which is not hard to do : at the end of the model file where the class is defined). Thanks a lot for this quick answer. Tony -- You received this message

[sqlalchemy] Table name without quoting with upper case

2010-11-25 Thread Tony Moutaux
code for this case, it would be great ! Tony PS : platform Sybase ASE 15.5 SQLAlchemy 0.6.5 with pyodbc over FreeTDS/Fedora -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com

[sqlalchemy] Re: adapt MSVarchar to SLString

2010-04-16 Thread Tony
here is the code: engine_src= create_engine('mssql://blah_blah_blah) engine_dst= create_engine('sqlite:///new.sqlite') metadata_src = MetaData(bind=engine_src,reflect=True) metadata_dst= MetaData(bind=engine_dst) for table in metadata_src.sorted_tables: dest_table =

[sqlalchemy] Re: adapt MSVarchar to SLString

2010-04-16 Thread Tony Tan
here is the code I am using to copy the database: engine_src = create_engine('mssql://blah_blah_blah) engine_dst = create_engine('sqlite:///new.sqlite') metadata_src = MetaData(bind=engine_src,reflect=True) metadata_dst = MetaData(bind=engine_dst) for table in metadata_src.sorted_tables:

[sqlalchemy] adapt MSVarchar to SLString

2010-04-15 Thread Tony
I was trying to copy a MS Sql server database to a Sqlite database (with SA 5.8), and get this exception: return typeobj.adapt(impltype) File C:\Python25\lib\site-packages\sqlalchemy\databases\mssql.py, line 685, in adapt collation=self.collation) TypeError: __init__() got an unexpected

[sqlalchemy] behavior of clear_mapper() function

2010-03-02 Thread Tony Tan
in it. 4. after all above step, the new mapping does not have the new 1:N relationship member in that mapped class. may be I need to show the code snippet to make it clear. But this is my first time to post here. I will wait and see. ---Tony -- You received this message because you

[sqlalchemy] Joining with a subquery

2008-09-07 Thread Tony Cebzanov
. So, I figured I'd provide an explicit join condition, but I don't know the right syntax to do it. I know the join() method takes an argument for the fields to join on, but how do I refer to the columns in the subquery table above? Thanks for any and all help. -Tony