Re: [sqlalchemy] AbstractConcreteBase and query_expression()

2020-03-25 Thread Mike Bayer
I don't really know, because AbstractConcreteBase works pretty poorly and it's 
better to use other patterns.

Try this workaround, which I have no idea if it helps in this case:

class A(...):

 # ...


 @classmethod
 def __declare_last__(cls):
 cls.__mapper__.with_polymorphic = ("*", cls.__mapper__.local_table)


otherwise provide a more complete example and I'll try to diagnose why it 
doesnt work for this case.


On Wed, Mar 25, 2020, at 12:30 PM, Benjamin Beguin wrote:
> Hi there,
> 
> I'm facing an issue with the use of AbstractConcreteBase class and a 
> @declarred_attr returning a query_expression()
> 
> 
> class A(AbstractConcreteBase, Base):
> @declared_attr
> def foo(cls):
> return query_expression()
> 
> 
> class B(A):
> ...
> 
> 
> class C(A):
> ...
> 
> 
> objects = db.session.query(A).options(with_expression(A.foo, 
> my_expression)).all()
> 
> 
> 
> B and C objects returned have the property foo but it is None
> The generated SQL query returns a value for the expression but the mapping 
> seems to be not effective 
> 
> Am I doing something wrong ?
> 

> --
>  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 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/a071d191-73d1-4519-8625-068903b3950c%40googlegroups.com
>  
> .

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/dd8b6a29-92b4-4238-a9cd-f7aa22f678c2%40www.fastmail.com.


Re: [sqlalchemy] looking for help building relationship that references an intermediate mixer table

2020-03-25 Thread Simon King
Do you need it to be an actual relationship? It's common to use an
association proxy for this:

https://docs.sqlalchemy.org/en/13/orm/extensions/associationproxy.html#simplifying-association-objects

Hope that helps,

Simon

On Fri, Mar 20, 2020 at 7:47 PM Mark Aquino  wrote:
>
> I'd like to create a relationship that joins a table linked to a related 
> table on a model:
>
> I have a Vessel class, a Well class, and a Batch class.
>
> Vessel and Well are related via a FK on Well (well.vessel_id) but Batch is a 
> many to many relationship with Well, e.g.
>
> Batch(Base):
>   id = Column(Integer)
>
> Well(Base):
>id = Column(Integer)
>vessel_id = Column(Integer)
>batches = relationship("Batch", secondary="mix_well_tracked_entity")
>
> Is it possible to make a relationship on Vessel to the Batches linked to its 
> wells?
>
> Vessel(Base):
>id = Column(Integer)
>wells = relationship("Well")
>wells_batches = relationship("Batch", ...???)
>
>
> select * from vessel v join well w on w.vessel_id = v.id join 
> mix_well_tracked_entity mix1 on mix1.well_id = w.id join batch b on b.id = 
> mix1.tracked_entity_id;
>
> --
> 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 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/54af97fe-9de7-4cb2-a4d9-96b33107c6af%40googlegroups.com.

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexc3eUFLWT0sPoqm%2B8RUM0eUKPhHq8kDiwFDPq6zBfn1Gw%40mail.gmail.com.


[sqlalchemy] AbstractConcreteBase and query_expression()

2020-03-25 Thread Benjamin Beguin
Hi there,

I'm facing an issue with the use of AbstractConcreteBase class and a 
@declarred_attr returning a query_expression()


class A(AbstractConcreteBase, Base):
@declared_attr
def foo(cls):
return query_expression()


class B(A):
 ...


class C(A):
 ...


objects = db.session.query(A).options(with_expression(A.foo, my_expression
)).all()



B and C objects returned have the property foo but it is None
The generated SQL query returns a value for the expression but the mapping 
seems to be not effective 

Am I doing something wrong ?

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/a071d191-73d1-4519-8625-068903b3950c%40googlegroups.com.


Re: [sqlalchemy] Cleaning metadata

2020-03-25 Thread Mike Bayer


On Wed, Mar 25, 2020, at 6:27 AM, Javier Collado Jiménez wrote:
> Hello, 
> I'm having a problem trying to cleanup sqlalchemy objects. My application has 
> a thread which handles DB connections. In some cases the thread dies and I 
> want to do a cleanup so, next time the thread is started it would be able to 
> reconnect again.
> The steps I tried are:
>  self.metadata.clear()
>  self.engine.dispose()
>  self.session.close()
>  self.conn.close()
> But when I start a new thread, errors like this appear:
> sqlalchemy.exc.ArgumentError: Column object 'column' already assigned to 
> Table 'table'

you should not be calling metadata.clear() and it looks like you are doing 
something where you are building Table objects on the fly, re-using the same 
Column objects a second time, leading to the error you are seeing. There should 
be a single MetaData object that is not part of an object, e.g. it's a global 
variable in your program (e.g. not "self.metadata").

Similarly for the engine, there should not be a "self.engine", there should be 
a single Engine object that is also a global variable in your program. It is 
also threadsafe and can be shared among multiple threads.


> 

> --
>  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 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/74117457-9968-4aa2-afa3-8ccb91e86937%40googlegroups.com
>  
> .

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c9216b53-fcc1-4782-9e18-be7c500f255f%40www.fastmail.com.


Re: [sqlalchemy] Cleaning metadata

2020-03-25 Thread Simon King
It's difficult to answer this question without knowing how your code
is structured. Are you reflecting your tables from the database, or
have you defined them statically?

What is the full stack trace when you get those errors?

Simon

On Wed, Mar 25, 2020 at 10:27 AM Javier Collado Jiménez
 wrote:
>
> Hello,
> I'm having a problem trying to cleanup sqlalchemy objects. My application has 
> a thread which handles DB connections. In some cases the thread dies and I 
> want to do a cleanup so, next time the thread is started it would be able to 
> reconnect again.
> The steps I tried are:
> self.metadata.clear()
> self.engine.dispose()
> self.session.close()
> self.conn.close()
> But when I start a new thread, errors like this appear:
> sqlalchemy.exc.ArgumentError: Column object 'column' already assigned to 
> Table 'table'
>
> --
> 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 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/74117457-9968-4aa2-afa3-8ccb91e86937%40googlegroups.com.

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexeUwzDhm1Hms7PfA752di6OmwG5BPoec5nfE6KKgw7D3g%40mail.gmail.com.


Re: [sqlalchemy] SQLAlchemy URI (in superset) to connect to SSL enabled DRUI UI

2020-03-25 Thread Simon King
I've never used Druid, but this is really a question for the pydruid
project, I don't know if any of those developers are on this list. It
looks like pydruid only recently started supporting self-signed
certificates (or allowing you to ignore certificate errors):

https://github.com/druid-io/pydruid/pull/180/files

The value of the "ssl_verify_cert" parameter gets passed as the
"verify" parameter to requests.post:

http://2.python-requests.org/en/v1.1.0/user/advanced/#ssl-cert-verification

Unfortunately, it doesn't look like the pydruid sqlalchemy adapter
allows the ssl_verify_cert option to be specified in the url:


https://github.com/druid-io/pydruid/blob/master/pydruid/db/sqlalchemy.py#L121

You might be able to use the connect_args option to create_engine:


https://docs.sqlalchemy.org/en/13/core/engines.html#custom-dbapi-connect-arguments

or you could use the "creator" argument to specify your own function
for creating the connection:


https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.creator

Hope that helps,

Simon

On Wed, Mar 25, 2020 at 12:15 AM Lakshman Pervatoj  wrote:
>
> Hi Everyone,
>
> Using SQLAlchemy I want to connect to Apache Druid DB through Druid UI which 
> is SSL enabled and also has local authentication
>
>
> druid+https://:@:/druid/v2/sql/
>
>
> And getting the below error:
>
>
> ERROR: {"error": "Connection failed!\n\nThe error message returned 
> was:\nHTTPSConnectionPool(host=‘, port=): Max retries exceeded 
> with url: /druid/v2/sql/ (Caused by SSLError(SSLCertVerificationError(1, 
> '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed 
> certificate
>
>
> How can we pass the certs
>
> --
> 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 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/c95ac471-9bdc-42bb-8121-82c8a62466f7%40googlegroups.com.

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexc9H%2BmkbszLjKXUdtSvfTJ0Y%2BD2vMzwJhbDjxyhA0TRCw%40mail.gmail.com.


[sqlalchemy] Cleaning metadata

2020-03-25 Thread Javier Collado Jiménez
Hello, 
I'm having a problem trying to cleanup sqlalchemy objects. My application 
has a thread which handles DB connections. In some cases the thread dies 
and I want to do a cleanup so, next time the thread is started it would be 
able to reconnect again.
The steps I tried are:
self.metadata.clear()
self.engine.dispose()
self.session.close()
self.conn.close()
But when I start a new thread, errors like this appear:
sqlalchemy.exc.ArgumentError: Column object 'column' already assigned to 
Table 'table'

-- 
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 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/74117457-9968-4aa2-afa3-8ccb91e86937%40googlegroups.com.