[sqlalchemy] Re: ImportError: cannot import name postgresql

2017-06-19 Thread shrey . chauhan

this is the stack trace :
[Mon Jun 19 18:11:01.431528 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] Traceback (most recent call last):
[Mon Jun 19 18:11:01.431548 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File 
"/var/lib/enclouden-orchestrator/enclouden-orchestrator.wsgi", line 10, in 

[Mon Jun 19 18:11:01.431616 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] imports =  
__import__("app",fromlist=['create_and_initialize_app'])
[Mon Jun 19 18:11:01.431627 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File "/var/lib/enclouden-orchestrator/app.py", line 6, 
in 
[Mon Jun 19 18:11:01.431677 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] from database import db, track_session_deletes
[Mon Jun 19 18:11:01.431691 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File 
"/var/lib/enclouden-orchestrator/database/__init__.py", line 10, in 
[Mon Jun 19 18:11:01.431728 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] from . import events, instances, pools, users, roles
[Mon Jun 19 18:11:01.431748 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File 
"/var/lib/enclouden-orchestrator/database/events.py", line 5, in 
[Mon Jun 19 18:11:01.431802 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] from .instances import Instance, OpenstackProject
[Mon Jun 19 18:11:01.431816 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File 
"/var/lib/enclouden-orchestrator/database/instances.py", line 2, in 
[Mon Jun 19 18:11:01.431893 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] from .types import GUID
[Mon Jun 19 18:11:01.431903 2017] [:error] [pid 18592] [remote 
10.11.12.15:128]   File 
"/var/lib/enclouden-orchestrator/database/types.py", line 5, in 
[Mon Jun 19 18:11:01.431950 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] from sqlalchemy.dialects import postgresql
[Mon Jun 19 18:11:01.431968 2017] [:error] [pid 18592] [remote 
10.11.12.15:128] ImportError: cannot import name postgresql



and yes this is mod_wsgi and daemon mode is present
this is the wsgi file

WSGIDaemonProcess ecnorchestrator user=apache processes=10 threads=1
WSGIScriptAlias /enclouden/orchestrator 
/var/lib/enclouden-orchestrator/enclouden-orchestrator.wsgi
WSGIScriptReloading On
WSGIPassAuthorization On


WSGIProcessGroup ecnorchestrator
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Require all granted
AddOutputFilterByType DEFLATE application/json





-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Adding a relationship for specific rows based on foreign value

2017-06-19 Thread mike bayer



On 06/19/2017 08:29 PM, Van Klaveren, Brian N. wrote:

Hi,

I want to represent a One to Many relationship with an additional default value 
that depends on a value in the foreign table.

I think what I want is something like the following:


class UserDatabase(Base):
 db_id = Column(Integer, primary_key=True)
 repo_id = Column(Integer, ForeignKey("UserDatabase.db_id"), nullable=True)
 name = Column(String(128))
 description = Column(Text)
 conn_host = Column(String(128))
 conn_port = Column(Integer)
 schemas = relationship("UserDatabaseSchema", lazy="dynamic")
 # Where is_default_schema == True
 default_schema = relationship("UserDatabaseSchema", primaryjoin=???, 
lazy="dynamic")

class UserDatabaseSchema(Base):
 schema_id = Column(Integer, primary_key=True)
 db_id = Column(Integer, ForeignKey("UserDatabase.db_id"))
 name = Column(String(128))
 description = Column(Text)
 is_default_schema = Column(Boolean)


but I'm not sure if primaryjoin is the proper argument for relationship and, if 
it is, what the expression should be. Or is this something that's best handled 
a different way?



you'd use primaryjoin for that and for examples see 
http://docs.sqlalchemy.org/en/rel_1_1/orm/join_conditions.html#specifying-alternate-join-conditions






Thanks,
Brian



--
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Only return single entity from query

2017-06-19 Thread Jonathan Vanasco
You're not joining anything onto the `rProductCategoryHistory` table, so 
depending on your DB you may be getting populated rows for rProduct that 
don't match anything.

you probably want something like this...

query = db.session.query(rProduct)\
.join(rProductHistoricalDetails, 
rProduct.most_recent_historical_details_id==rProductHistoricalDetails.id)\
.join(rProductReviewsHistoricalDetails, 
rProduct.most_recent_historical_reviews_entry==rProductReviewsHistoricalDetails.id)\
.order_by(rProductHistoricalDetails.time_updated.desc())

unless you missed joining rProductCategoryHistory.

you should try writing a raw sql query that gets the right data.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Adding a relationship for specific rows based on foreign value

2017-06-19 Thread Van Klaveren, Brian N.
Hi,

I want to represent a One to Many relationship with an additional default value 
that depends on a value in the foreign table.

I think what I want is something like the following:


class UserDatabase(Base):
db_id = Column(Integer, primary_key=True)
repo_id = Column(Integer, ForeignKey("UserDatabase.db_id"), nullable=True)
name = Column(String(128))
description = Column(Text)
conn_host = Column(String(128))
conn_port = Column(Integer)
schemas = relationship("UserDatabaseSchema", lazy="dynamic")
# Where is_default_schema == True
default_schema = relationship("UserDatabaseSchema", primaryjoin=???, 
lazy="dynamic")

class UserDatabaseSchema(Base):
schema_id = Column(Integer, primary_key=True)
db_id = Column(Integer, ForeignKey("UserDatabase.db_id"))
name = Column(String(128))
description = Column(Text)
is_default_schema = Column(Boolean)


but I'm not sure if primaryjoin is the proper argument for relationship and, if 
it is, what the expression should be. Or is this something that's best handled 
a different way?


Thanks,
Brian

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Only return single entity from query

2017-06-19 Thread Ryan Weinstein
  query = db.session.query(rProductCategoryHistory,rProduct)\ 
.join(rProduct,rProduct.r_id==rProductCategoryHistory.r_id)\ 
.join(rProductHistoricalDetails, 
rProductHistoricalDetails.id==rProduct.most_recent_historical_details_id)\ 
.join(rProductReviewsHistoricalDetails,rProductReviewsHistoricalDetails.id==rProduct.most_recent_historical_reviews_entry)\
 
.order_by(desc(rProductHistoricalDetails.time_updated))\

I've got this query that only works if I put rProductCategoryHistory and 
rProduct 
into it, but I only care about the rProduct instances returned. Whats the 
best way to have this same query while only returning rProduct instances?

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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

2017-06-19 Thread jens . troeger
Thank you, that worked.

Alas, I might have to use an explicit association object 

 
after all if I want to set the *is_manager* value in the association table. 
Simply assigning a new User to the Team.managers list (as defined by the 
relationship()) does not translate into *is_manager* to be set to True.

Jens


On Thursday, June 15, 2017 at 6:22:09 AM UTC-7, Simon King wrote:
>
> Actually I think in this case you could probably leave the "secondary" 
> argument as the association table itself, but change the join 
> condition via the "primaryjoin" parameter. Something like this 
> (completely untested): 
>
> class User(Base): 
> id = Column(Integer, primary_key=True) 
> 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,   
> wrote: 
> > Thanks Simon. While this seems to have worked, I only run into the next 
> > error. Mind you, I’m somewhat new to Alchemy and my SQL is rather rusty 
> at 
> > the moment. My current approach 
> > 
> > managed_teams = relationship("Team", 
> >  secondary="join(user_team_association, 
> > user_team_association.c.is_manager==true)", 
> >  backref="managers") 
> > 
> > seems to be an incomplete join. I’ll look into this tomorrow… 
> > Jens 
> > 
> > 
> > On Thursday, June 15, 2017 at 6:25:00 PM UTC+10, Simon King wrote: 
> >> 
> >> Table objects put columns under the ".c" attribute, so you probably 
> >> need "user_team_association.c.is_manager". 
> >> 
> >> 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 
> > 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+...@googlegroups.com . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Concise, Pythonic query syntax

2017-06-19 Thread Bryan Jones
Mike,

Thanks for your careful analysis and thoughtful comments. I appreciate the 
time you spent to think about this. I agree that this does represent 
simpler syntax for a narrow class of common operations. Per your advice, 
I'll work this up into a package and post it on pypi. Thanks for the 
feedback!

Bryan

On Thursday, June 15, 2017 at 3:11:47 PM UTC-5, Bryan Jones wrote:
>
> All,
>
> While working on my SQLAlchemy-based application, I noticed an opportunity 
> to provide a more concise, Pythonic query syntax. For example, 
> User['jack'].addresses produces a Query for the Address of a User named 
> jack. I had two questions
>
>1. Has someone already done this? If so, would you provide a link?
>2. If not, would this be reasonable for inclusion in SQLAlchemy, 
>either as an ORM example, or as a part of the core code base? If so, I can 
>submit a pull request.
>
> A quick comparison of this statement to the traditional approach:
>
> User['jack']   .addresses
> Query([]).select_from(User).filter(User.name == 'jack').join(Address).
> add_entity(Address)
>
> A few more (complete) examples of this approach:
> # Ask for the full User object for jack.
> User['jack'].to_query(session)
> # Ask only for Jack's full name.
> User['jack'].fullname.to_query(session)
> # Get all of Jack's addresses.
> User['jack'].addresses.to_query(session)
> # Get just the email-address of all of Jack's addresses.
> User['jack'].addresses.email_address.to_query(session)
> # Get just the email-address j...@yahoo.com of Jack's addresses.
> User['jack'].addresses['j...@yahoo.com'].to_query(session)
> # Ask for the full Address object for j...@yahoo.com.
> Address['j...@yahoo.com'].to_query(session)
> # Ask for the User associated with this address.
> Address['j...@yahoo.com'].user.to_query(session)
> # Use a filter criterion to select a User with a full name of Jack Bean.
> User[User.fullname == 'Jack Bean'].to_query(session)
> # Use two filter criteria to find the user named jack with a full name of 
> Jack Bean.
> User['jack'][User.fullname == 'Jack Bean'].to_query(session)
> # Look for the user with id 1.
> User[1].to_query(session)
>
> Tested on Python 3.6.1, Windows 10, SQLAlchemy 1.1.10. I've attached the 
> code, and a HTML document of the code with helpful hyperlinks.
>
> Bryan
> -- 
> Bryan A. Jones, Ph.D.
> Associate Professor
> Department of Electrical and Computer Engineering
> 231 Simrall / PO Box 9571
> Mississippi State University
> Mississippi State, MS 39762
> http://www.ece.msstate.edu/~bjones
> bjones AT ece DOT msstate DOT edu
> voice 662-325-3149
> fax 662-325-2298
>
> Our Master, Jesus Christ, is on his way. He'll show up right on
> time, his arrival guaranteed by the Blessed and Undisputed Ruler,
> High King, High God.
> - 1 Tim. 6:14b-15 (The Message)
>

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] SQLAlchemy 1.1.11 Released

2017-06-19 Thread mike bayer



SQLAlchemy release 1.1.11 is now available.

Release 1.1.11 includes a series of fixes providing 
forwards-compatibility with a variety new behaviors in supported 
databases. A few other core fixes and one ORM-related fix is also included.


Changelog for 1.1.11 is at: 
http://www.sqlalchemy.org/changelog/CHANGES_1_1_11


SQLAlchemy 1.1.11 is available on the Download Page at: 
http://www.sqlalchemy.org/download.html


--
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


SQLAlchemy 1.1.11 Released

2017-06-19 Thread mike bayer



SQLAlchemy release 1.1.11 is now available.

Release 1.1.11 includes a series of fixes providing 
forwards-compatibility with a variety new behaviors in supported 
databases. A few other core fixes and one ORM-related fix is also included.


Changelog for 1.1.11 is at: 
http://www.sqlalchemy.org/changelog/CHANGES_1_1_11


SQLAlchemy 1.1.11 is available on the Download Page at: 
http://www.sqlalchemy.org/download.html


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] ImportError: cannot import name postgresql

2017-06-19 Thread mike bayer
if more of a stack trace is present in error_log, that would help, also 
to clarify if this is mod_wsgi, and if daemon mode is present or not.



On 06/19/2017 06:48 AM, shrey.chau...@invicto.in wrote:

Hi,
I am using a remote postgres server:

*PostgreSQL 9.6.2
sqlalchemy 1.1.10*

running my app on Apache webserver, but whe i try hitting any API i get 
this error- *ImportError:* *cannot import name postgresql*
this is the line which is creating issues :-*from sqlalchemy.dialects 
import postgresql*



I am using sqlalchemy.dialects, I am not able to understand why is this 
happening, when i was using locally it was working fine, does remote 
server makes a difference? or the reason is httpd

can someone help on this?


--
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 post to this group, send email to sqlalchemy@googlegroups.com 
.

Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: SQLAlchemy JTI subqueryload bug

2017-06-19 Thread mike bayer
thanks!  if they're deep "incorrect query" things in the ORM like this, 
I fix those really fast.   Inconvenient things with Core / typing system 
etc., not so much :)




On 06/19/2017 12:12 AM, Sherwin Yu wrote:
Mike, thanks for responding and fixing this so quickly 
(https://bitbucket.org/zzzeek/sqlalchemy/issues/4011/joined-subclass-to-2-level-subquery-load#comment-37650645)!


Just wanted to take a moment to express my gratitude for your work on 
SQLA -- it's absolutely critical to our company (Benchling). A few of 
our other engineers have reported issues before and you've always been 
quick to respond. Thank you!


On Wednesday, June 14, 2017 at 10:23:06 PM UTC-7, Sherwin Yu wrote:



We found a bug involving filtering a JTI relation and
subqueryloading. The emitted SQL for the subqueryload does not
correctly join the child and parent JTI tables, resulting in a cross
product.

Info:

  * psql (PostgreSQL) 9.5.7
  * SQLAlchemy 0.9.10

Suppose we have the following relations (see full repro insructions
below):

  * Dept
  * Owner
  o dept_id
  * Milestone
  o owner_id
  * Sprint (subclass of Milestone)
  o id references milestone.id 


When doing the following query:


Sprint.query.filter(Sprint.id.in_([1])).options(db.subqueryload(Sprint.owner).subqueryload(Owner.dept)).all()

We see the three following queries, the third of which has an
incorrect inner SELECT:

SELECTsprint.id   AS sprint_id,milestone.id 
  AS milestone_id, milestone.milestone_type AS 
milestone_milestone_type, milestone.owner_id AS milestone_owner_id
FROM milestone JOIN sprint ONmilestone.id   =sprint.id 

WHEREsprint.id   IN (%(id_1)s)
INFO:sqlalchemy.engine.base.Engine:{'id_1': 1}

SELECTowner.id   AS owner_id, owner.dept_id AS 
owner_dept_id, anon_1.milestone_owner_id AS anon_1_milestone_owner_id
FROM (SELECT DISTINCT milestone.owner_id AS milestone_owner_id
FROM milestone JOIN sprint ONmilestone.id   =sprint.id 

WHEREsprint.id   IN (%(id_1)s)) AS anon_1 JOIN owner ONowner.id 
  = anon_1.milestone_owner_id ORDER BY anon_1.milestone_owner_id
INFO:sqlalchemy.engine.base.Engine:{'id_1': 1}

SELECTdept.id   AS dept_id, owner_1.dept_id AS 
owner_1_dept_id
FROM (SELECT DISTINCT milestone.owner_id AS milestone_owner_id
FROM milestone, sprint
WHEREsprint.id   IN (%(id_1)s)) AS anon_1 JOIN owner AS owner_1 
ONowner_1.id   = anon_1.milestone_owner_id JOIN dept ONdept.id 
  = owner_1.dept_id ORDER BY owner_1.dept_id
INFO:sqlalchemy.engine.base.Engine:{'id_1': 1}

In particular, the inner SELECT on the third query, |SELECT DISTINCT
milestone.owner_id AS milestone_owner_id FROM milestone, sprint
WHERE sprint.id  IN (%(id_1)s)| (corresponding to
|subqueryload(Owner.dept)|) is selecting from tables milestone and
sprint without specifying a join condition, which results in the a
cross product of the two tables (the entire milestone table is
returned along with sprint.id  = 1).

The temporary work around we found was to replace
|.filter(Sprint.id.in_([1]))| to |.filter(Milestone.id.in_([1]))| ,
which then emits this query instead:

SELECTdept.id   AS dept_id, owner_1.dept_id AS 
owner_1_dept_id
FROM (SELECT DISTINCT milestone.owner_id AS milestone_owner_id
FROM milestone
WHEREmilestone.id   IN (%(id_1)s)) AS anon_1 JOIN owner AS owner_1 
ONowner_1.id   = anon_1.milestone_owner_id JOIN dept ONdept.id 
  = owner_1.dept_id ORDER BY owner_1.dept_id

Which avoids taking the cross product of milestone and sprint.
(Note, this only works since sprint.id  is the
foreign key to milestone.id , so filtering by
milestone.id  is sufficient)


Repro

# Create some tables:
CREATE TABLE dept (id integer PRIMARY KEY);
CREATE TABLE owner (id integer PRIMARY KEY, dept_id integer, CONSTRAINT 
owner_dept_id_dept_id_fkey FOREIGN KEY (dept_id) REFERENCES dept (id));
CREATE TABLE milestone (id integer PRIMARY KEY, milestone_type VARCHAR(64) 
NOT NULL, owner_id integer, CONSTRAINT milestone_owner_id_owner_id_fkey FOREIGN 
KEY (owner_id) REFERENCES dept (id));
CREATE TABLE sprint (id integer PRIMARY KEY, CONSTRAINT 
sprint_id_milestone_id_fkey FOREIGN KEY (id) REFERENCES milestone (id));

class Milestone(db.Model):
 __tablename__ = 'milestone'
 id = db.Column(db.Integer, primary_key=True)

 milestone_type = db.Column(db.String(64), nullable=False)
 

[sqlalchemy] ImportError: cannot import name postgresql

2017-06-19 Thread shrey . chauhan
Hi, 
I am using a remote postgres server:


*PostgreSQL 9.6.2sqlalchemy 1.1.10*

running my app on Apache webserver, but whe i try hitting any API i get 
this error- *ImportError:* *cannot import name postgresql*
this is the line which is creating issues :-* from sqlalchemy.dialects 
import postgresql*


I am using sqlalchemy.dialects, I am not able to understand why is this 
happening, when i was using locally it was working fine, does remote server 
makes a difference? or the reason is httpd
can someone help on this?


-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.