Re: [sqlalchemy] Controlling table dependency for flushing

2018-09-14 Thread Simon King
directly, SQLAlchemy probably won't understand the dependency. Does using a relationship fix your problem? Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and V

Re: [sqlalchemy] Delete, bulk delete, and Sessions—some clarification needed.

2018-09-13 Thread Simon King
Python, to see which objects in the session are about to be deleted. This is impossible to do in the general case, but it may work for simple criteria. It will raise an error if the criteria aren't supported by the evaluator, but note the warning in the docs that "the expression evaluator current

Re: [sqlalchemy] filter like using a string in a column of timestamps without time zones - postgres

2018-09-11 Thread Simon King
ime >= starttime, Orders.ef_time < endtime) orders_objects = session.query(Orders).filter(condition).all() Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete,

Re: [sqlalchemy] How to customize base declarative class to add naming conventions

2018-09-04 Thread Simon King
alembic) ? > Also would it works for unique constraint on multiple column or do we have to > name them explicitly. > Is it important to you to do this via a mixin? declarative_base accepts a "metadata" parameter, so something like this should work: metadata = MetaData(naming_con

Re: [sqlalchemy] Re: Relationship to child with 2 foreginKey from same Parent column

2018-09-03 Thread Simon King
Here's a version which I *think* does what you want. There are a couple of things that you might want to note. First, in your paste, Conversation.user1 and Conversation.user2 are integer columns, but you are assigning User objects to those properties. That's not the way SQLAlchemy works - you

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
On Tue, Aug 28, 2018 at 5:53 PM Simon King wrote: > > On Tue, Aug 28, 2018 at 4:32 PM 'Brian DeRocher' via sqlalchemy > wrote: > > > > Hey all, > > > > I'm writing some automated tests for some legacy python code using a > > psycopg2 connection. I'd like

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
directly to the connection: http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites Would that work for your situation? Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.s

Re: [sqlalchemy] Encoding troubles with pythong, mysql and utf8mb4

2018-08-22 Thread Simon King
("error") ...which will give you an exception and a stack trace, so you can see where these warnings are coming from. Simon On Wed, Aug 22, 2018 at 10:37 AM wrote: > Sorry for my last messy message, here's a better version. > > That's a good question actually. If you follow my

Re: [sqlalchemy] Encoding troubles with pythong, mysql and utf8mb4

2018-08-22 Thread Simon King
I've never used Pandas, so this may not make any sense, but where does the column "VARIABLE_VALUE" come from? Is it a column in your dataframe? Simon On Wed, Aug 22, 2018 at 8:52 AM wrote: > > I get the following warnings, when trying to save a simple dataframe to &

Re: [sqlalchemy] How to ignore primary key errors on insert

2018-08-21 Thread Simon King
If you are using SQLAlchemy core, there's this: http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#insert-on-conflict-upsert Does that meet your needs? Simon On Tue, Aug 21, 2018 at 3:36 AM Hardik Sanghavi wrote: > > Did this get resolved or are we to still

Re: [sqlalchemy] Re: Generic Associations - table_per_association: parent attribute

2018-07-30 Thread Simon King
, and then query the appropriate parent table. Simon On Sat, Jul 28, 2018 at 7:39 AM Sven wrote: > > Hi Mike, > > Ok, let's forget everything I said before, it is too confusing. > > I propose to start from the table_per_association example: > > http://docs.sqlalchemy.org/en/

Re: [sqlalchemy] So, Sqlalchemy migration tool is not support chang column type ?

2018-07-26 Thread Simon King
t/ops.html#alembic.operations.Operations.alter_column.params.postgresql_using Simon On Thu, Jul 26, 2018 at 11:47 AM Yingchen Zhang wrote: > > use PostgreSQL change column type need `cast` like `ALTER TABLE invite_code > ALTER COLUMN created_at::timestamp TYPE TIMESTAMP WITH TIME ZONE `, > but sqlalchemy aut

Re: [sqlalchemy] So, Sqlalchemy migration tool is not support chang column type ?

2018-07-26 Thread Simon King
compare_type parameter to True, or to a custom callable function. The feature works well in most cases, but is off by default so that it can be tested on the target schema first. It can also be customized by passing a callable here; see the section Comparing Types for details. """ Ho

Re: [sqlalchemy] M2M relationship back_populates KeyError

2018-07-02 Thread Simon King
the user and keyword tables, and doesn't have any other behaviour, you probably don't want to define it as a mapped class at all. Instead, use the Table constructor, as in the first example at http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#many-to-many. If you really do want to treat Us

Re: [sqlalchemy] three table join with confusing results

2018-06-01 Thread Simon King
What does the SQL look like for each of your queries? Can you produce a standalone script that demonstrates the problem? You could use my script from https://groups.google.com/forum/#!topic/sqlalchemy/GNIBQMvMRg8 as a template. Thanks, Simon On Fri, Jun 1, 2018 at 2:41 PM wrote: > &g

Re: [sqlalchemy] Re: Compare two schemas of two different DB's using Diff

2018-05-22 Thread Simon King
) Simon On Tue, May 22, 2018 at 12:26 PM, Neethu Abhinav <neethuabhin...@gmail.com> wrote: > And can you also help me the imports, that is required to use this tool? > > > On Tuesday, May 22, 2018 at 4:54:03 PM UTC+5:30, Neethu Abhinav wrote: >> >> Yes, that

Re: [sqlalchemy] Compare two schemas of two different DB's using Diff

2018-05-22 Thread Simon King
test/ The URIs it expects will be the same ones accepted by sqlalchemy.create_engine(): http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please pr

Re: [sqlalchemy] Issue with Sqlalchemy in exe file(created using pyinstaller)

2018-05-22 Thread Simon King
You'll probably need to take this up with the PyInstaller folks (http://www.pyinstaller.org/support.html). SQLAlchemy uses pkg_resources entry points to load database dialects, and I don't know how well PyInstaller supports those. Sorry, Simon On Mon, May 21, 2018 at 8:02 PM, <bin...@gmail.

Re: [sqlalchemy] polymorphic_on / polymorphic_identity randomly 'ignored'

2018-05-18 Thread Simon King
nstance will be stored in the session's identity map. As long as that instance exists in the session, SQLAlchemy will not construct an instance of the appropriate subclass (otherwise the session would contain 2 objects representing the same row in the database, which SQLAlchemy tries to avo

Re: [sqlalchemy] Issue with Sqlalchemy in exe file(created using pyinstaller)

2018-05-16 Thread Simon King
ould be appreciated. > It's possible that pyinstaller hasn't included the sqlalchemy_teradata package in its output. Perhaps adding "--hidden-import sqlalchemy_teradata" to your command line when building the exe might help? Simon -- SQLAlchemy - The Python SQL Toolkit and Object

Re: [sqlalchemy] trying to retrieve data from multiple tables with .join()

2018-05-14 Thread Simon King
ould use one of the eager loading options: http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#joined-eager-loading For example: import sqlalchemy.orm as saorm user = User.query.options(saorm.joinedload('area')).get(1) This would automatically add the join between the u

Re: [sqlalchemy] Confused about Many-to-Many outerjoin

2018-05-01 Thread Simon King
sa.and_(subs.c.user_id == User.user_id, User.name == 'joe'), ) q = (session.query(Channel, User.user_id) .outerjoin(userjoin)) print q for (channel, userid) in q.all(): print channel.channel_name, userid Ho

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
No, you'll need to convert that to the equivalent SQL. On Fri, Apr 27, 2018 at 3:14 PM, Jeremy Flowers <jeremy.g.flow...@gmail.com> wrote: > But can you still do things like slice(0,5)? Struggling to get that to work > atm... > > On Fri, Apr 27, 2018 at 2:48 PM, Simon King <s

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
it would help. I'll > have a dig around. > There are a few examples of using text() with the ORM here: http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#using-textual-sql session.execute() behaves more like the Core-level connection.execute(), which is described here: http:/

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
what the right SQL syntax should be. At this point I would echo Mike's question: why can't you just use "text()"? Simon On Fri, Apr 27, 2018 at 10:07 AM, Jeremy Flowers <jeremy.g.flow...@gmail.com> wrote: > Well the printed oracle sql dialect now works correctly - when I hack it an > r

Re: [sqlalchemy] Python Sqlalchemy filter by date range

2018-04-25 Thread Simon King
the tutorial at http://docs.sqlalchemy.org/en/latest/orm/tutorial.html. Hope that helps, Simon -- 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 htt

Re: [sqlalchemy] simple: get max id in table

2018-04-24 Thread Simon King
t; function instead: q3 = select([func.max(dst_tab.c.id)]) http://docs.sqlalchemy.org/en/latest/core/selectable.html#sqlalchemy.sql.expression.select Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-19 Thread Simon King
against a sqlite database. Good luck! Simon On Wed, Apr 18, 2018 at 10:21 PM, su-sa <sachdeva.sugandh...@gmail.com> wrote: > @Mike, Jonathan and Simon - Thank you so much for all your efforts. I hope I > can fix the problem soon in the dialect :-) > > P.s. I have finally bee

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-18 Thread Simon King
Ah, I didn't notice this part of your query: .filter(..., Partsupp.ps_supplycost == session.query(func.min(Partsupp.ps_supplycost))) I'm not sure exactly what SQL you are aiming for there, but I think you need to add .correlate (or maybe .correlate_except) to that inner query. Simon On Wed

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-18 Thread Simon King
assumption that they are part of the outer query. Simon On Wed, Apr 18, 2018 at 4:20 PM, su-sa <sachdeva.sugandh...@gmail.com> wrote: > > But if I am not mistaken, the from clause of the query is generated by > SQLAlchemy and the database driver or the dialect has no influence on this

Re: [sqlalchemy] How to get ForeignKey from Relationship property

2018-04-11 Thread Simon King
assing by defining them dynamically. Can you explain why you are trying to create columns and relationships dynamically? There might be a different way to approach the problem. Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code

Re: [sqlalchemy] is this intentional or a bug with subquery join

2018-04-04 Thread Simon King
column in subquery.c > Where is the traceback raised? On the evaluation of the "subquery.c.event_timestamp" expression? That wouldn't really make any sense. Or is it when the query itself is evaluated? We need to see at least the traceback, or better a script to reproduce. Simon -- SQLAlchemy - Th

Re: [sqlalchemy] rollback() practice

2018-03-29 Thread Simon King
ssion management "around" the rest of your application code, and handle exceptions in just one place. There's a section in the docs with more details: http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#session-faq-whentocreate Hope that helps, Simon -- SQLAlchemy -

Re: [sqlalchemy] Session's dialect's server_version_info may be None? (Execution order dependency)

2018-02-21 Thread Simon King
Session itself or with the mapped Table objects being operated upon. This connection represents an ongoing transaction, which remains in effect until the Session is instructed to commit or roll back its pending state. """ Hope that helps, Simon -- SQLAlchemy - The Python SQL To

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-16 Thread Simon King
OK, so what's not working? On Fri, Feb 16, 2018 at 10:55 AM, <eugene.de...@gmail.com> wrote: > Yes session.is_active is True. > I really sure, because i log this operation. > > пятница, 16 февраля 2018 г., 13:50:51 UTC+3 пользователь Simon King написал: >> >> You

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-16 Thread Simon King
You haven't explained in what way it's not working with your latest iteration. The last code you posted only called session.close() if session.is_active was true. Are you sure you really are closing the session? Simon On Fri, Feb 16, 2018 at 10:02 AM, <eugene.de...@gmail.com>

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-15 Thread Simon King
When you say your first execute function doesn't work, what do you mean? Do you get an error? Do the results not show up in the database? I don't think there's any need for session.begin() http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session.begin Simon

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-15 Thread Simon King
/docs/0.12/appcontext/#locality-of-the-context). Hope that helps, Simon On Thu, Feb 15, 2018 at 9:52 AM, <eugene.de...@gmail.com> wrote: > Hello, Simon! > So what better way? > Something like this? > SESSION = sessionmaker(bind=engine, autocommit=True) > > > > @decorato

Re: [sqlalchemy] Define one to one and many-to-many relationship using SQLAlchemy Core

2018-02-15 Thread Simon King
t Core. Can you explain what you're looking for in more detail? Thanks, Simon -- 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://stackoverflo

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-14 Thread Simon King
er. If you are *absolutely certain* that will never happen, adding the "finally" section will probably improve things, but I would recommend that you try to structure your app a little differently, so that the session creation and teardown happen at the beginning and end of the web request. Hop

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-14 Thread Simon King
The pattern you should be aiming for is one in which a fresh transaction is started for every web request that touches the database, and that the transaction is closed at the end of the request. How are you ensuring that at the moment? Simon On Wed, Feb 14, 2018 at 12:51 PM, <eugene

Re: [sqlalchemy] running py.test

2018-02-14 Thread Simon King
PYTHONPATH that is being imported instead of the real library? Simon On Tue, Feb 13, 2018 at 3:58 PM, su-sa <sachdeva.sugandh...@gmail.com> wrote: > Hi Simon, > > I installed both pytest and mock using pip install py.test mock in the > virtualenv. I am using anaconda python. B

Re: [sqlalchemy] Re: Register function example (perhaps) to remove tab, newline or carriage return from column.

2018-02-14 Thread Simon King
ars): for c in chars: col = sa.func.REPLACE(col, c, '') return col def removewhitespace(col): return removechars(col, '\t\r\n') print removewhitespace(Jobdtl.jobdtl_cmd) Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www

Re: [sqlalchemy] Re: Why does join() method not have join type as an argument?/Is left-join the default..

2018-02-09 Thread Simon King
As you say, .join() produces an inner join by default. You can specify isouter=True to get a left outer join (or call the .outerjoin method instead), and full=True to get a full outer join. I think you'd get a cross join if you just didn't call the .join() method at all. Simon On Fri, Feb 9

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
Out of interest, why would you not write: print( session.query(Jobmst.jobmst_type, Jobmst.jobmst_name) .first() ) The call to with_entities seems unnecessary. Simon On Fri, Feb 9, 2018 at 12:27 PM, Jeremy Flowers <jeremy.g.flow...@gmail.com> wrote: > And that can be s

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
The chaining-friendly method you are looking for is probably with_entities(): http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_entities Simon On Fri, Feb 9, 2018 at 11:52 AM, Jeremy Flowers <jeremy.g.flow...@gmail.com> wrote: > From watching your

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
The main point you should take from Mike's original reply is: .values() is a weird method and it's pretty old, usually people just set the columns up front You probably shouldn't use it. On Fri, Feb 9, 2018 at 11:45 AM, Jeremy Flowers wrote: > Also this didn't

Re: [sqlalchemy] Query a query in SQLAlchemy

2018-02-09 Thread Simon King
defined, you can add further restrictions to it simply by calling its ".filter()" method. Alternatively you can convert the query to a subquery and then build another query around that. http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#using-subqueries Hope that helps, Simon -- SQLAl

Re: [sqlalchemy] running py.test

2018-02-09 Thread Simon King
somebody please help me to solve the problem. > How have you installed these libraries? Are you using virtualenv? If so, are pytest and mock both installed in the virtualenv? Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post exam

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2018-02-09 Thread Simon King
are the scope and lifetime of the above vs. > using a listener as suggested by Michael? > I'm pretty sure variables set using "SET GLOBAL" will not survive a database restart. You'd need to specify it on the server command line or config file if you wanted it to be persistent. Simo

Re: [sqlalchemy] Implementing historical tables

2018-02-01 Thread Simon King
nto the history table. The versioned_rows.py example is more like what you described, converting what would have been an UPDATE into an INSERT on the same table. Both examples use the "before_flush" session event to implement the versioning, so other parts of your code don't need to be

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-15 Thread Simon King
Yes, if you can't find where you are creating new Satellite instances, I'd probably stick an assert statement in Satellite.__init__ and see where it gets triggered. Simon On Mon, Jan 15, 2018 at 10:34 AM, Ruben Di Battista <rubendibatti...@gmail.com> wrote: > Dear Simon, > &g

Re: [sqlalchemy] About multithread session (scoped session)

2018-01-15 Thread Simon King
the results that another thread has written: https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels https://sqlite.org/isolation.html https://www.postgresql.org/docs/9.1/static/transaction-iso.html Simon On Mon, Jan 15, 2018 at 9:39 AM, <ginger...@gmail.com> wrote: &

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-15 Thread Simon King
On Sat, Jan 13, 2018 at 3:31 PM, Ruben Di Battista <rubendibatti...@gmail.com> wrote: > > > On Friday, January 12, 2018 at 10:54:49 AM UTC+1, Simon King wrote: >> >> If I understand your code correctly, scheduler.propagate() creates a >> large number of Passage ins

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-12 Thread Simon King
for that relationship, and then you'll probably need to explicitly add the passages you want to *keep* to the session instead. Hope that helps, Simon On Fri, Jan 12, 2018 at 2:10 AM, Mike Bayer <mike...@zzzcomputing.com> wrote: > I can't give you much detail except to say the unique obje

Re: [sqlalchemy] Polymorphic discriminator not being added to update queries

2018-01-11 Thread Simon King
st be added manually, even for single table inheritance. So I guess it's not strictly a bug, and there's probably a good reason why it's not being done. It might be simply that it's a bit complicated to implement so it hasn't been done yet. Simon -- SQLAlchemy - The Python SQL Toolkit and Obje

Re: [sqlalchemy] Building relatively complex dynamic queries in SQLAlchemy

2018-01-03 Thread Simon King
d it up one step at a time, something like this: q = session.query(YourObject) if price is not None: q = q.filter(YourObject.price == price) if category is not None: q = q.filter(YourObject.category == category) if sizes: q = q.join(Size).filter(Size.size.in_(sizes)) if colors:

Re: [sqlalchemy] Help writing query - "where most recent is true, but any other is false"

2017-12-14 Thread Simon King
d write this in SqlAlchemy? You ought to be able to build up the above SQL incrementally using the Query.subquery() method. See the example at: http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#using-subqueries If you wanted to use the EXISTS version of the second condition, you would need something like:

Re: [sqlalchemy] How to make polymorphic identity condition involving a join not be a subselect

2017-11-27 Thread Simon King
sa.Column(sa.String(16)) __mapper_args__ = { 'polymorphic_on': name, } def execute(self, task): raise NotImplemented class DoStuffTaskType(TaskType): __mapper_args__ = { 'polymorphic_on': 'do_stuff_task', } def execute(self, task): # do stu

Re: [sqlalchemy] Disable `session_identity_map` for `_instance_processor`

2017-11-23 Thread Simon King
ate_session, scopefunc=manager.get_current_tenant) Base.query = Session.query_property As long as you call manager.set_current_tenant whenever you switch to querying a different tenant, this ought to work. But note that all of this confusion and complexity stems from using scoped sessions and Bas

Re: [sqlalchemy] Disable `session_identity_map` for `_instance_processor`

2017-11-23 Thread Simon King
per HTTP request, the standard HTTP > request pattern is one Session per request.There's no problem in > that case. You mentioned you have some non-flask applications that > want to communicate with multiple tenants in one Session. > OP, can you describe in more detail why these a

Re: [sqlalchemy] Re: Required properties of first arg to bulk_insert_mappings

2017-11-21 Thread Simon King
/latest/faq/performance.html#i-m-inserting-400-000-rows-with-the-orm-and-it-s-really-slow) If that still isn't fast enough, I guess you'll need to prepare a data file and then use the appropriate DB-specific mechanism to load it. I don't think SQLAlchemy has any specific tools for that. Simon

Re: [sqlalchemy] Re: Required properties of first arg to bulk_insert_mappings

2017-11-21 Thread Simon King
on.execute() accepts any Core construct) Hope that helps, Simon On Mon, Nov 20, 2017 at 9:16 PM, Skip Montanaro <skip.montan...@gmail.com> wrote: > I've narrowed down my problem space a bit. Consider this simple code: > > from sqlalchemy import (Integer, String, Column, MetaData, c

Re: [sqlalchemy] Confusion over session.dirty, query, and flush

2017-11-16 Thread Simon King
Can you explain why you actually want to do this? There might be better options than before_flush, but we'd need to know exactly what you're trying to do first. Simon On Thu, Nov 16, 2017 at 12:55 PM, <jens.troe...@gmail.com> wrote: > That makes sense, thank you, Simon! > > Regar

Re: [sqlalchemy] Confusion over session.dirty, query, and flush

2017-11-16 Thread Simon King
that haven't yet been committed. There are various ways to do what you want, depending on how your code is structured. One possibility is to use a Session event such as before_flush to set a flag saying that there are uncomitted changes in the database. http://docs.sqlalchemy.org/en/latest

Re: [sqlalchemy] Two classes linked to the same backref attribute in a third classe

2017-11-15 Thread Simon King
; (backref_key, self, m)) >> sqlalchemy.exc.ArgumentError: Error creating backref 'parent' on >> relationship 'Animal.description': property of that name exists on mapper >> 'Mapper|Description|descriptions' >> >> >> It seems impossible to link the classes to the

Re: [sqlalchemy] SQLAlchemy leaves MySQL open connections

2017-11-13 Thread Simon King
On Mon, Nov 13, 2017 at 4:35 PM, Ahmad Javed <ahmadjaved...@gmail.com> wrote: > Thank you Simon. Appreciate your response. Just using session.remove() at > the end of each request is not closing the connection and leave open > connections in MySQL database. One more thing I want

Re: [sqlalchemy] SQLAlchemy leaves MySQL open connections

2017-11-13 Thread Simon King
cation starts up. Disposing the engine (or the pool) should never be necessary. If all your per-request DB access goes through the scoped session, and you are calling session.remove() at the end of each request, connections should be returned to the pool properly. Simon -- SQLAlchemy - The P

Re: [sqlalchemy] Excluding attributes from polymorphic hierarchy

2017-10-27 Thread Simon King
en the table. I don't want them to be shared by > the subclasses. > > When I query one of the Concretes, the ACB mapper is updated with the > "start" and "end" attributes, and then the Concretes are expected to > implement the attributes on the mapper level(which is n

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-25 Thread Simon King
get_bind_args helper function) Your overridden version of _execute_and_instances is passing a clause in the "mapper" parameter, which seems wrong. Somehow you need to fix that, perhaps by using the _get_bind_args helper. Simon On Wed, Oct 25, 2017 at 1:02 PM, Антонио Антуан <a.ch

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-25 Thread Simon King
What does self._mapper_zero() return in your RoutingQuery._execute_and_instances method? Simon On Wed, Oct 25, 2017 at 11:52 AM, Антонио Антуан <a.ch@gmail.com> wrote: > Any news here? > > суббота, 21 октября 2017 г., 18:42:47 UTC+3 пользователь Антонио Антуан > на

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
ither be an instance of sqlalchemy.orm.mapper.Mapper, or None, in which case "if mapper:" is a valid and concise way to write it. Comparing to None might be strictly more accurate, but it shouldn't be necessary. Simon On Fri, Oct 20, 2017 at 3:17 PM, Антонио Антуан <a.ch@gmail.com> wrote: > Really,

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
is point is some sort of SQL construct (such as a column object or mapped property), rather than an actual mapper. You don't say which version of SQLAlchemy you are using, but since you've overridden _execute_and_instances, I wonder if you need to use something like query._bind_mapper() as used by _ge

Re: [sqlalchemy] SQLAlchemy enum in external file

2017-10-20 Thread Simon King
traps.html#executing-the-main-module-twice> When you import a module, it gets cached in sys.modules under its "fully qualified module name", so it doesn't matter how many times you run "import foo", the module is only loaded once. However, the script that you initially

Re: [sqlalchemy] Postgres database: open and close connection

2017-10-06 Thread Simon King
) "engine.connect()" will raise an exception if it fails to connect. Hope that helps, Simon -- 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

Re: [sqlalchemy] sqlalchemy foreignkey relation with inheritance

2017-09-22 Thread Simon King
On Fri, Sep 22, 2017 at 9:42 AM, Simon King <si...@simonking.org.uk> wrote: > On Fri, Sep 22, 2017 at 8:18 AM, John Smith <johnsmith31...@gmail.com> wrote: >> I have the following database schema: >> >> Table "Parent": >> 1. id - primary key id

Re: [sqlalchemy] sqlalchemy foreignkey relation with inheritance

2017-09-22 Thread Simon King
parent = relationship(Parent, foreign_keys=[parent_id]) __mapper_args__ = { 'polymorphic_identity':'Child', 'inherit_condition': id == Parent.id, } engine = create_engine('sqlite:///:memory:', echo=True) Session = sessionmaker() Session.configure(bind=engine) Base.metadata.create_a

Re: [sqlalchemy] A "after flush before commit" event

2017-09-15 Thread Simon King
Could you pair a before_commit handler with an after_flush_postexec handler? The before_commit one would set a flag to say that you are committing, and the after_flush_postexec one would look for that flag before proceeding. Simon On Fri, Sep 15, 2017 at 12:08 AM, <m...@benchling.com>

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
b/master/flask_sqlalchemy/__init__.py#L851 Simon -- 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 d

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
On Thu, Sep 14, 2017 at 10:59 AM, Ankur Kumar <ankur.kumar.o...@gmail.com> wrote: >> Hello Simon, > > > Thanks, > I donot want to read uncommitted data. > > I want to read committed data by one API server from another API server. >> >> > > From an

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
ysql.com/doc/refman/5.7/en/innodb-transaction-isolation-levels.html http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#setting-transaction-isolation-levels (Obviously with lower transaction isolation comes the possibility of reading inconsistent data and so on) Hope that helps, Si

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-31 Thread Simon King
with a batch sizes of 10, 50 and 100. You'll run more queries but I suspect each query will perform better. Simon On Wed, Aug 30, 2017 at 10:02 PM, Ken MacKenzie <deviloc...@gmail.com> wrote: > With a batch size of 1 based on the original selection, no improvement. > > I am going

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-31 Thread Simon King
query and potentially leave you open to SQL injection. d) Are your values unicode strings or byte strings? If unicode, does the encoding match what the database expects? If none of those are issues for you, the textual version is probably pretty safe. Simon On Wed, Aug 30, 2017 at 5:30 PM, Ken

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
'), ) statement = sa.delete(table, whereclause=condition) batchparams = [{'pk1': v[0], 'pk2': v[1]} for v in id_batch] session.execute(statement, batchparams) Simon On Wed, Aug 30, 2017 at 4:28 PM, Ken MacKenzie <deviloc...@gmail.com> wrote: > After the current sorted profile finishes I wi

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
(id_batch) * len(cls.SQL_PK)? You could try playing with your batch sizes to see what sort of effect that has. Simon On Wed, Aug 30, 2017 at 4:01 PM, Ken MacKenzie <deviloc...@gmail.com> wrote: > So I implemented this version with one change. I moved this line: > > cols = [getat

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
Textual SQL is not DB-neutral in general. Luckily, in this case you shouldn't even need it. Try something like this: for x in id_batch: cols = [getattr(cls, colname) for colname in cls.SQL_PK] pkf = [(col == v) for (col, v) in zip(cols, x)] and_cond = and_(*pkf) or_cond.append(a

Re: [sqlalchemy] SQLAlchemy 1.1 cause core dump committing multiple dirty records outside of function where mutation happens

2017-08-22 Thread Simon King
or refactor (b/c commit happens via a decorator). > > # Main question > > Why does this happen exactly for multiple records and why did this work in > 1.0 but does not in 1.1? What platform are you running this on, and how have you installed MySQLdb and SQLAlchemy? If you ugraded SQLAlchemy

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-21 Thread Simon King
Are you flushing the same session that was used to load the record? What session does get_instance use? Simon On Mon, Aug 21, 2017 at 7:47 AM, pravin battula <pravin.batt...@gmail.com> wrote: > I did as below. But didn't work. Am i missing anything else. > > def update_rec

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
No, but you can trivially write your own function to do it: def updateobj(obj, data): for key, value in data.items(): setattr(obj, key, value) Simon On Fri, Aug 18, 2017 at 3:14 PM, pravin battula <pravin.batt...@gmail.com> wrote: > The solution which you gave will work b

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
but: product_live_item.attr1 = value1 product_live_item.attr2 = value2 session.flush() Is that what you meant? Simon -- 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

Re: [sqlalchemy] Raising on usage of attribute in SQL queries

2017-08-17 Thread Simon King
o you mean the amount of typing you have to do each time you disable a column (creating the hybrid properties)? If so, you might be able to use the events system to create those properties automatically. For example, you could try listening for the "after_configured" mapper event, then inspect the cla

Re: [sqlalchemy] Guidance for mapping tables dynamically

2017-07-31 Thread Simon King
;FAIL").join(Main).all()) > I haven't run your code, so this answer may not be appropriate, but in general, you can create a relationship when using classical mappings by passing a "properties" parameter to the mapper() function, something like this: mapper(TempTable, temp_tabl

Re: [sqlalchemy] Is there a way to configure session.commit() so that it automatically return the committed instance's class.__name__ + primary id?

2017-07-25 Thread Simon King
, you could use ORM events (http://docs.sqlalchemy.org/en/latest/orm/events.html) to be notifed when an instance is inserted/updated/deleted. Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

Re: [sqlalchemy] SQLAlchemy won't connect correctly but pyodbc and pymssql will

2017-07-04 Thread Simon King
king around with pdb in the scalar() function: https://bitbucket.org/zzzeek/sqlalchemy/src/8d740d6bd6b8bcc061713443120c67e611cdcb34/lib/sqlalchemy/engine/result.py?at=rel_1_1_11=file-view-default#result.py-1212 Simon On Tue, Jul 4, 2017 at 2:39 PM, Paul Morel <paul.mo...@tartansolutions.com>

Re: [sqlalchemy] Optimize SQLAlchemy query

2017-06-30 Thread Simon King
n't, it has to construct those objects and link them together. Processing 22352 rows in 0.91 seconds doesn't seem bad to me. If you can reply with the bare PG and SA core timings, we may have a better idea of how to optimise your query. Simon -- SQLAlchemy - The Python SQL Toolkit and Object R

Re: [sqlalchemy] execute Stored procedure.

2017-06-28 Thread Simon King
t/search.html?q=%22stored+procedure%22_keywords=yes=default If not, how would you normally call the stored procedure if you weren't using SQLAlchemy? Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide a

Re: [sqlalchemy] Re: Wierdness with JSONB / Python dictionary

2017-06-28 Thread Simon King
t for the property value, but instead to use something that will notify SA when its contents change. SA has an extension that provides MutableDict and MutableList classes, as well as tools to build your own more specialized types: http://docs.sqlalchemy.org/en/latest/orm/extensions/mutable.html H

Re: [sqlalchemy] Re: How to do scalar sub selects with the ORM correctly?

2017-06-15 Thread Simon King
You might be interested in this thread: https://groups.google.com/forum/#!msg/sqlalchemy/8z0XGRMDgCk/tazeIUsdDgAJ Simon On Thu, Jun 15, 2017 at 1:53 PM, 'mike waites' via sqlalchemy <sqlalchemy@googlegroups.com> wrote: > Interestingly I've just discovered the concept of Bundle

Re: [sqlalchemy] Adding filters to association (secondary) relationships

2017-06-15 Thread Simon King
e) managed_teams = relationship( 'Team', secondary=user_team_association_table, primaryjoin=sa.and_(user_team_association_table.c.user_id == id, user_team_association_table.c.is_manager==sa.true()), ) Simon On Thu, Jun 15, 2017 at 12:26 PM, <jens.troe...@gma

Re: [sqlalchemy] Adding filters to association (secondary) relationships

2017-06-15 Thread Simon King
Table objects put columns under the ".c" attribute, so you probably need "user_team_association.c.is_manager". Simon On Thu, Jun 15, 2017 at 12:11 AM, <jens.troe...@gmail.com> wrote: > Thank you Mike, the composite joins look like something close to wha

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