Re: [sqlalchemy] automap_base with mapped class

2017-03-11 Thread Vijaya Sekar
Yeah I done it thank u mike

-- 
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] can't debug a failed relationship declaration

2017-03-11 Thread Jonathan Vanasco
I can't seem to declare a valid relationship in my application, but can do 
so as a self-contained example.

the (working) example on the relevant columns is this:

class IpAddress(Base):
__tablename__ = 'ip_address'
id = Column(Integer, primary_key=True)
ip_address__cidr = Column(sqlalchemy.dialects.postgresql.CIDR, 
nullable=False)
ip_range_id__primary = Column(Integer, ForeignKey("ip_range.id"), 
nullable=True)

#  _session = object_session(self)
ip_range__primary = relationship(
"IpRange",
primaryjoin="IpAddress.ip_range_id__primary==IpRange.id",
uselist=False,
)

ip_ranges_in = relationship(
"IpRange",

primaryjoin="IpAddress.ip_address__cidr.op('<<')(IpRange.ip_range__cidr)",
viewonly=True,
)


class IpRange(Base):
__tablename__ = 'ip_range'
id = Column(Integer, primary_key=True)
ip_range__cidr = Column(sqlalchemy.dialects.postgresql.CIDR, 
nullable=False)

ip_addresses__primary = relationship(
"IpAddress",
primaryjoin="IpRange.id==IpAddress.ip_range_id__primary",
)


I can't create a valid `IpAddress.tracked_ip_ranges` relationship in my 
application.  It complains that it wants a foreign(), then a remote(), then 
just fails.

Does anyone have tips on troubleshooting what is going on?  something is 
causing this to fail, but I can't figure out what.

-- 
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] Looks like there is no event to catch "before" a rollback happens

2017-03-11 Thread mike bayer



On 03/11/2017 10:15 AM, mike bayer wrote:



On 03/10/2017 11:12 AM, Alessandro Molina wrote:



On Fri, Mar 10, 2017 at 3:40 PM, mike bayer > wrote:

If this is truly, "unexpected error but we need to do things",
perhaps you can use before_flush() to memoize the details you need
for a restore inside of session.info .

An event hook can be added but it would need to be carefully
considered what the specific use case for this hook is.   For
example I'm not sure "before_rollback()" is really what this should
be, it likely should be "on flush exception" similar to how engine
does it.


My specific need is related to https://github.com/amol-/depot/issues/36

DEPOT allows loading files associated to database data.
In case of a rollback DEPOT deletes the files that got uploaded.

That works in case of `.flush()` + `.rollback()` because it gathers the
history of the entity and the changed files in `before_flush`, but if a
rollback is issued without a flush it currently lacks an event from
which it can get the state of the objects and their history before the
rollback.



Looking at the code for how the events are called I would say that
moving the after_rollback() event call to be before the attributes are
reset might be more appropriate.   The after_commit() event works this
way, that is, inside of after_commit() things have not yet been expired.
  This would be an example of how critical it is that we consider really
deeply how these events are implemented.   Throwing them in quickly is
how these design mistakes occur.



propose after_rollback() emit before the snapshot is cleared at 
https://bitbucket.org/zzzeek/sqlalchemy/issues/3934/call-after_rollback-before-accounting. 
  If you can evaluate the patch at 
https://gerrit.sqlalchemy.org/#/c/334/ that would be helpful.  Note that 
you still cannot emit SQL in this event.












--
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] Looks like there is no event to catch "before" a rollback happens

2017-03-11 Thread mike bayer



On 03/10/2017 11:12 AM, Alessandro Molina wrote:



On Fri, Mar 10, 2017 at 3:40 PM, mike bayer > wrote:

If this is truly, "unexpected error but we need to do things",
perhaps you can use before_flush() to memoize the details you need
for a restore inside of session.info .

An event hook can be added but it would need to be carefully
considered what the specific use case for this hook is.   For
example I'm not sure "before_rollback()" is really what this should
be, it likely should be "on flush exception" similar to how engine
does it.


My specific need is related to https://github.com/amol-/depot/issues/36

DEPOT allows loading files associated to database data.
In case of a rollback DEPOT deletes the files that got uploaded.

That works in case of `.flush()` + `.rollback()` because it gathers the
history of the entity and the changed files in `before_flush`, but if a
rollback is issued without a flush it currently lacks an event from
which it can get the state of the objects and their history before the
rollback.



Looking at the code for how the events are called I would say that 
moving the after_rollback() event call to be before the attributes are 
reset might be more appropriate.   The after_commit() event works this 
way, that is, inside of after_commit() things have not yet been expired. 
  This would be an example of how critical it is that we consider 
really deeply how these events are implemented.   Throwing them in 
quickly is how these design mistakes occur.









--
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] automap_base with mapped class

2017-03-11 Thread mike bayer



On 03/11/2017 01:17 AM, Vijaya Sekar wrote:

from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine, MetaData
lists = ['employees','address']
engine = create_engine("sqlite:///chinook.db")
metadata = MetaData()
metadata.reflect(engine, only=lists)
Base = automap_base(metadata=metadata)
Base.prepare()
User = Base.classes.employees


you can say:

list(Base.classes)[0]

but this is not an ordered dictionary so you can't be assured of what 
"0" is.


You have a list of names, why not use those?

User = Base.classes[lists[0]]










In the above How can i achieve mapping the classes without mention the class 
explicitly.

i.e User = Base.classes.employees

How can achieve same result by using the lists[0]

--
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.