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

2018-02-14 Thread George
I have searched the documentation but didn't find anything useful. Please guide me in the right direction. -- 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.

Re: [sqlalchemy] Re: Relationships - crash when class instantiation

2018-02-14 Thread Mike Bayer
On Wed, Feb 14, 2018 at 1:47 PM, Sven wrote: > Hello, > > Maybe, the way to find out is to press ctrl-C during your test and then send > me the stack trace. > > > I am unfortunately not able to get any stack trace with ctrl-C. I don't know > why. It has not effect during the crash which last a few

[sqlalchemy] Re: Relationships - crash when class instantiation

2018-02-14 Thread Sven
Hello, Maybe, the way to find out is to press ctrl-C during your test and then send me the stack trace. I am unfortunately not able to get any stack trace with ctrl-C. I don't know why. It has not effect during the crash which last a few seconds. Haven't seen many endless loop issues over the

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

2018-02-14 Thread Jonathan Vanasco
On Wednesday, February 14, 2018 at 6:49:47 AM UTC-5, Simon King wrote: > For what it's worth, I would do it something like this: > that's elegant. I'd rather do that now too. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example

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

2018-02-14 Thread Simon King
I think there are a couple of problems with this. 1. You are calling scoped_session and sessionmaker every time the decorated function is called, which is unnecessary. sessionmaker returns a factory function for creating sessions, so you typically only have one sessionmaker() call in your applicat

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

2018-02-14 Thread eugene . deneb
Decorator like this engine = create_engine( 'mssql+pymssql://{LOGIN}:{PASSWORD}@{HOST}/{DATABASE}?charset={CHARSET}&timeout={TIMEOUT}'.format(**DATABASE), isolation_level='READ COMMITTED' ) def decorator_with_args(decorator_to_enhance): """ https://habrahabr.ru/post/141501/

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, wrote: > If I run t

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

2018-02-14 Thread eugene . deneb
If I run tests where all functions run one-by-one - all tests passed. But when i run web app and functions can call almost in parallel then i have a problem, then there are problems - transactions can block each other. I tried to set the isolation level of SNAPSHOT and READ COMMITTED, but it did

Re: [sqlalchemy] running py.test

2018-02-14 Thread Simon King
The error is coming from here: https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/testing/mock.py So I guess you could start by adding some print statements in that file to see where the exception is being raised. Perhaps you have a different "mock.py" somewhere on the PYTHONPATH tha

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

2018-02-14 Thread eugene . deneb
Hello, Mike! In my web app i have many selects like session.execute(select([table1]).where(condition)) and not so much updates, inserts and deletes like session.execute(update(table1).where(condition).values(**values)) session.execute(insert(table1).values(**values)) session.execute(delete(table1).

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

2018-02-14 Thread Simon King
On Fri, Feb 9, 2018 at 7:38 PM, Jeremy Flowers wrote: > And I do want to use this functionality repeatedly on many columns, hence > the idea of registering a function. > For what it's worth, I would do it something like this: def removechars(col, chars): for c in chars: col = sa.func