Re: [sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Leslie Luyt
This is fantastic, I didn't realise you could define a table using a sql expression. I am always amazed by how amazing and configurable SQLAlchemy is. Thank you so much for the help with this. PS. I am a huge fan. Please give Dilly a pat for me =). On Saturday, October 21, 2017 at 5:14:28 AM

Re: [sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Mike Bayer
note I inadvertently used a previous form for the first GroupProfile example. The two forms are: class GroupProfile(Base): __table__ = ( select([Group.group_id, Profile]). select_from(join(Group, ProfileGroupRole).join(Profile)). distinct().alias() ) ... and

Re: [sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 4:52 PM, Leslie Luyt wrote: > Here is my example: > > class Role(Base): > __tablename__ = 'role' > role_id = Column(BigInteger, primary_key=True) > role_name = Column(String, nullable=False) > role_description = Column(String) > >

Re: [sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Leslie Luyt
Here is my example: class Role(Base): __tablename__ = 'role' role_id = Column(BigInteger, primary_key=True) role_name = Column(String, nullable=False) role_description = Column(String) class Group(Base): __tablename__ = 'group' group_id = Column(BigInteger,

[sqlalchemy] Re: SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Sven
Exactly what I was looking for and it works (even applied to my project). I tried so many things these last days and the solution now looks so simple. Thank you very much ! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code,

Re: [sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 3:15 PM, Mike Bayer wrote: > On Fri, Oct 20, 2017 at 2:40 PM, Sven wrote: >> Thank you for your answer. >> >> I'm sorry, I have not been clear enough regarding the "__abstract__ = True". >> >> I suppose that I will have to

Re: [sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 2:40 PM, Sven wrote: > Thank you for your answer. > > I'm sorry, I have not been clear enough regarding the "__abstract__ = True". > > I suppose that I will have to add this to a lot of classes for the following > reasons : > 1) because it will allow

Re: [sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Sven
Thank you for your answer. I'm sorry, I have not been clear enough regarding the "__abstract__ = True". I suppose that I will have to add this to a lot of classes for the following reasons : 1) because it will allow me to persist the classes one by one and still be able to run and test the

Re: [sqlalchemy] Is ARRAY supported in MySQL?

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 1:35 PM, sqlalchemy_mysql wrote: > That's correct. MySQL doesn't support. I see people workaround by > serializing it to string/text and store and retrieve so was wondering > SQLAlchemy has some support like that. Seems like NO. You use a TypeDecorator

Re: [sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Mike Bayer
CONTINUING ! sorry On Fri, Oct 20, 2017 at 11:55 AM, Sven Dumay wrote: > > *I tried other things and I found the following solution :* > > from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta > from sqlalchemy import Column, Integer > > class

Re: [sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 11:55 AM, Sven Dumay wrote: > Hello, > > I am actually working on an existing project (an online-game) which is > already advanced and pretty consequent. > > My goal is to replace the save system actually based on Pickle by > SQLAlchemy. Not so easy

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 11:05 AM, Simon King wrote: > The "is not None" is important when checking a variable that may > contain a ClauseElement, precisely because ClauseElement defines that > __bool__ method. > > However, in Session.get_bind(), "mapper" is not supposed to

Re: [sqlalchemy] DESC index in test

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 9:39 AM, Gijs Molenaar wrote: > Hi! > > I don't think this is standard SQL? At least MonetDB doesn't support it, and > I can't find a way to disable this apart from overriding the test: > >

Re: [sqlalchemy] Is ARRAY supported in MySQL?

2017-10-20 Thread sqlalchemy_mysql
That's correct. MySQL doesn't support. I see people workaround by serializing it to string/text and store and retrieve so was wondering SQLAlchemy has some support like that. Seems like NO. On Friday, October 20, 2017 at 10:25:33 AM UTC-7, Mike Bayer wrote: > > On Thu, Oct 19, 2017 at 6:38 PM,

Re: [sqlalchemy] Some sqlalchemy unittests running twice while testing with an external dialect

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 9:32 AM, su-sa wrote: > I ran the unittests of SQLAlchemy with an external dialect and observed that > some Tests can 2 times and also had different results. > > Does somebody know what the reason behing it could be ? we've communicated

Re: [sqlalchemy] Different results if the tests are ran multiple number of times

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 9:27 AM, su-sa wrote: > I am trying to test sqlalchemy with an external dialect. To do the Tests > with the requirements specified by this external dialect, I used the > --requirements Parameter. The Test results of some Tests varied when I

Re: [sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Mike Bayer
On Fri, Oct 20, 2017 at 8:53 AM, Leslie Luyt wrote: > I am trying to integrate with an existing user-group-role table structure > where a user can belong to many groups and have multiple roles on each > group. > > > I found a similar question to this, however it does

Re: [sqlalchemy] Is ARRAY supported in MySQL?

2017-10-20 Thread Mike Bayer
On Thu, Oct 19, 2017 at 6:38 PM, sqlalchemy_mysql wrote: > Sorry I don't see any references in doc. I tried using array type but got > this error > > can't render element of type > > Compiler 0x110949e90> can't render element of type 'sqlalchemy.sql.sqltypes.ARRAY'> > > Here

Re: [sqlalchemy] sqlalchemy.select().group_by(expr) doesn't use label of expression, while .order_by(expr) does

2017-10-20 Thread Mike Bayer
On Thu, Oct 19, 2017 at 4:25 AM, Gijs Molenaar wrote: > > > Op donderdag 19 oktober 2017 03:10:21 UTC+2 schreef Mike Bayer: >> >> On Wed, Oct 18, 2017 at 7:38 AM, Gijs Molenaar >> wrote: >> > hi! >> > >> > >> > Not sure if this a bug or something I

[sqlalchemy] Re: SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Sven Dumay
Version of Python : 3.4.0 Version of SQLAlchemy : 1.2.0b2 -- 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

[sqlalchemy] SQLAlchemy : declarative_base and metaclass conflict

2017-10-20 Thread Sven Dumay
Hello, I am actually working on an existing project (an online-game) which is already advanced and pretty consequent. My goal is to replace the save system actually based on Pickle by SQLAlchemy. Not so easy because I have to deal with the existing classes and there is a lot of work to do

Re: [sqlalchemy] SQLAlchemy enum in external file

2017-10-20 Thread Jonathan Vanasco
sorry. i'm getting over a code and in my fever-dream state thought I was making something clear with an analogy. looking at this, and literally everything else I wrote yesterday, I'm amazed it's at least in english. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
The "is not None" is important when checking a variable that may contain a ClauseElement, precisely because ClauseElement defines that __bool__ method. However, in Session.get_bind(), "mapper" is not supposed to contain a ClauseElement. It should either be an instance of

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Антонио Антуан
Really, `mapper` contains this: . But does it changes something? I already encountered this problem in my code, when I checked sqla-objects existance without "is not None", project was broken. Is it normal to omit that condition in sqlalchemy code? I use: >>> sqlalchemy.__version__ '1.0.19'

Re: [sqlalchemy] SQLAlchemy enum in external file

2017-10-20 Thread TazMainiac
On Fri, Oct 20, 2017 at 3:58 AM, Simon King wrote: > This is a subtle python gotcha based on how the import system works. > It doesn't have anything to do with SQLAlchemy. > >

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
On Fri, Oct 20, 2017 at 2:15 PM, Антонио Антуан wrote: > Hi. > I use my own `RoutingSession` and `RoutingQuery` implementation, most of it > inspired by `sqlalchemy.ext.horizontal_shard`: > > class RoutingSession(Session): > def get_bind(self, mapper=None, clause=None,

[sqlalchemy] DESC index in test

2017-10-20 Thread Gijs Molenaar
Hi! I don't think this is standard SQL? At least MonetDB doesn't support it, and I can't find a way to disable this apart from overriding the test: https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/testing/suite/test_reflection.py#L128 greetings, - Gijs -- SQLAlchemy - The

[sqlalchemy] Some sqlalchemy unittests running twice while testing with an external dialect

2017-10-20 Thread su-sa
I ran the unittests of SQLAlchemy with an external dialect and observed that some Tests can 2 times and also had different results. Does somebody know what the reason behing it could be ? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

[sqlalchemy] Different results if the tests are ran multiple number of times

2017-10-20 Thread su-sa
I am trying to test sqlalchemy with an external dialect. To do the Tests with the requirements specified by this external dialect, I used the --requirements Parameter. The Test results of some Tests varied when I ran the Tests multiple number of times. I am´doing the testing currently on the

[sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Антонио Антуан
Hi. I use my own `RoutingSession` and `RoutingQuery` implementation, most of it inspired by `sqlalchemy.ext.horizontal_shard`: class RoutingSession(Session): def get_bind(self, mapper=None, clause=None, shard_id=None, **kwargs): original_bind = None try:

[sqlalchemy] SQLAlchemy Many-to-Many Users, Groups, Roles

2017-10-20 Thread Leslie Luyt
I am trying to integrate with an existing user-group-role table structure where a user can belong to many groups and have multiple roles on each group. I found a similar question to this, however it does not allow for multiple roles: Many-to-many declarative SQLAlchemy definition for

Re: [sqlalchemy] generate raw insert statement

2017-10-20 Thread Антонио Антуан
Excuse me, missed your response. Found this soultiuon: >>> print(compile_query(Foo.__table__.insert().values(bar='zoo').compile( Session.bind.dialect)) INSERT INTO foos (bar) VALUES ('zoo') пятница, 13 октября 2017 г., 19:41:29 UTC+3 пользователь Mike Bayer написал: > > On Fri, Oct 13, 2017

Re: [sqlalchemy] SQLAlchemy enum in external file

2017-10-20 Thread Simon King
On Thu, Oct 19, 2017 at 9:10 PM, TazMainiac wrote: > > > On Thu, Oct 19, 2017 at 2:25 PM, Jonathan Vanasco > wrote: >> >> On Thursday, October 19, 2017 at 11:55:49 AM UTC-4, Taz Mainiac wrote: >>> >>> So - a morning spent googling does not turn up any