Re: [sqlalchemy] Custom Compilation

2020-03-18 Thread Mike Bayer


On Wed, Mar 18, 2020, at 1:23 PM, Soumaya Mauthoor wrote:
> Hello
> 
> I have two uses cases:
> 
> (1) drop cascade as option
> I know I can use custom compilation to add cascade for postgres databases 
> using this example:
> https://stackoverflow.com/questions/38678336/sqlalchemy-how-to-implement-drop-table-cascade
> Is it possible to use custom compilation to add cascade as an optional 
> keyword argument to drop()? 


drop() doesn't accept any optional keyword arguments so you're best off making 
your own subclass of DropTable called DropTableCascade and just executing it: 
conn.execute(DropTableCascade(mytable))


> 
> (2) overwriting func functions
> Is it possible to overwrite func.greatest to return func.max for SQLite?

generic functions are used for this. Since "max" is a multiple-typed function 
you can use a helper class called ReturnTypeFromArgs:

from sqlalchemy.sql.functions import ReturnTypeFromArgs
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import literal_column
from sqlalchemy.sql import func

from sqlalchemy.dialects import sqlite


class greatest(ReturnTypeFromArgs):
 pass


@compiles(greatest, "sqlite")
def _render_max(elem, compiler, **kw):
 return "max(%s)" % compiler.process(elem.clauses)


print(func.greatest(literal_column("foo")))
print(func.greatest(literal_column("foo")).compile(dialect=sqlite.dialect()))





> 
> I'm trying to learn more about custom compilation in general. This page is 
> very helpful: 
> http://docs.sqlalchemy.org/en/latest/core/compiler.html
> 
> Are there other resources you recommend?
> 
> Soumaya
> 
> 

> --
>  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/CAN14jWQGC%2BzfNAEfFCiRHmTbCsXq2NrWGPoE0qpNhcTWx55-iw%40mail.gmail.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/be8be4ca-7393-48de-bbb8-32b649bd7a13%40www.fastmail.com.


[sqlalchemy] Custom Compilation

2020-03-18 Thread Soumaya Mauthoor
Hello

I have two uses cases:

(1) drop cascade as option
I know I can use custom compilation to add cascade for postgres databases
using this example:
https://stackoverflow.com/questions/38678336/sqlalchemy-how-to-implement-drop-table-cascade
Is it possible to use custom compilation to add cascade as an optional
keyword argument to drop()?

(2) overwriting func functions
Is it possible to overwrite func.greatest to return func.max for SQLite?

I'm trying to learn more about custom compilation in general. This page is
very helpful:
http://docs.sqlalchemy.org/en/latest/core/compiler.html

Are there other resources you recommend?

Soumaya

-- 
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/CAN14jWQGC%2BzfNAEfFCiRHmTbCsXq2NrWGPoE0qpNhcTWx55-iw%40mail.gmail.com.


[sqlalchemy] Re: Problem with inserting row containing a value with type PATH of postgres with geoalchemy2

2020-03-18 Thread Jonathan Vanasco
I'm glad it's up and running for you!

-- 
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/1ba8c778-4264-4f22-ae0e-f15470a3cb7d%40googlegroups.com.


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

2020-03-18 Thread Jonathan Vanasco
Tony,

Mike helped me with a similar problem a few weeks ago:

https://groups.google.com/d/msg/sqlalchemy/k4a-v2ebeJM/bj73xd4CFwAJ

In his suggestion, I stash some mapper configuration data into `info`, then 
use the `mapper_configured` event to audit my configuration requirements. 

-- 
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/e2f485df-460a-4215-bfdd-5d9ffa7aba53%40googlegroups.com.


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

2020-03-18 Thread Mike Bayer


On Wed, Mar 18, 2020, at 11:42 AM, Mike Bayer wrote:
> 
> 
> On Wed, Mar 18, 2020, at 11:22 AM, Tony Hignett wrote:
>> 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 release. viewonly 
>> relationships should not be mutated (this warning may be suppressed after 10 
>> occurrences)
>>  (self, other),
>> ```
>> 
>> I've read some of the related issues, e.g. 
>> https://github.com/sqlalchemy/sqlalchemy/issues/5149, 
>> https://github.com/sqlalchemy/sqlalchemy/issues/ 
>> 4993, but I don't 
>> understand how backref comes into it. We don't want to mutate anything along 
>> the backref.
>> 
>> Is there a way of expressing a two-way read-only relation?
> 
> you should remove the backref. have the "viewonly" relationship stand alone 
> by itself.

also if you want 'children1' to also be a viewonly relationship, set that up 
separately.


> 
> 
>> 
>> The code looks like
>> ```
>> class Parent(Base):
>>  pass
>> 
>> class Child1(Base):
>> 
>>  @declared_attr
>>  def parent(cls):
>>  return orm.relationship(
>>  Parent,
>>  ...,
>>  viewonly=True,
>>  backref="children1"
>>  )
>> 
>> class Child2(Base):
>>  [etc]
>> 
>> 

>> --
>> 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/660cedf0-7066-42fe-93bc-d6e4d223b05c%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/40c0410d-0233-4abc-aae7-bfe728495647%40www.fastmail.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/9844a940-fa9c-4b15-b031-7f507f299af3%40www.fastmail.com.


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

2020-03-18 Thread Mike Bayer


On Wed, Mar 18, 2020, at 11:22 AM, Tony Hignett wrote:
> 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 release. viewonly 
> relationships should not be mutated (this warning may be suppressed after 10 
> occurrences)
>  (self, other),
> ```
> 
> I've read some of the related issues, e.g. 
> https://github.com/sqlalchemy/sqlalchemy/issues/5149, 
> https://github.com/sqlalchemy/sqlalchemy/issues/ 
> 4993, but I don't 
> understand how backref comes into it. We don't want to mutate anything along 
> the backref.
> 
> Is there a way of expressing a two-way read-only relation?

you should remove the backref. have the "viewonly" relationship stand alone by 
itself.


> 
> The code looks like
> ```
> class Parent(Base):
>  pass
> 
> class Child1(Base):
> 
>  @declared_attr
>  def parent(cls):
>  return orm.relationship(
>  Parent,
>  ...,
>  viewonly=True,
>  backref="children1"
>  )
> 
> class Child2(Base):
>  [etc]
> 
> 

> --
>  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/660cedf0-7066-42fe-93bc-d6e4d223b05c%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/40c0410d-0233-4abc-aae7-bfe728495647%40www.fastmail.com.


[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 release.  viewonly 
relationships should not be mutated (this warning may be suppressed after 
10 occurrences)
  (self, other),
```

I've read some of the related issues, e.g. 
https://github.com/sqlalchemy/sqlalchemy/issues/5149, 
https://github.com/sqlalchemy/sqlalchemy/issues/ 
4993, but I don't 
understand how backref comes into it. We don't want to mutate anything 
along the backref.

Is there a way of expressing a two-way read-only relation?

The code looks like
```
class Parent(Base):
pass

class Child1(Base):

@declared_attr
def parent(cls):
return orm.relationship(
Parent,
...,
viewonly=True,
backref="children1"
)

class Child2(Base):
[etc]


-- 
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/660cedf0-7066-42fe-93bc-d6e4d223b05c%40googlegroups.com.


[sqlalchemy] Re: Problem with inserting row containing a value with type PATH of postgres with geoalchemy2

2020-03-18 Thread Christos Ch
Yes you are right thank you!

On Tuesday, March 17, 2020 at 7:41:58 PM UTC+2, Jonathan Vanasco wrote:
>
>
> On Tuesday, March 17, 2020 at 12:06:36 PM UTC-4, Christos Ch wrote:
>>
>> I am running a service from a docker container
>>
>
> The error is from psycopg2 and stating the function is not available on 
> the PostgreSQL server.  This is most likely because PostGIS is not 
> installed on the server (which could be in the docker container, or 
> elsewhere) or needs to be enabled for that database.
>

-- 
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/af99ced8-b361-4691-a7ee-41e4df90830e%40googlegroups.com.