Re: [sqlalchemy] Problems with sqlalchemy and timestamps

2017-03-07 Thread karl . lattimer
Yeah, you're sort of right - I wasn't getting the error reported for the 
initial failure, which was causing me pain. My logs aren't really up to 
scratch we're using docker with AWS and it's a PITA at times.

I'm still not sure what was causing the original problem, but with some 
extra work it appears to have gone away. I have some overhauling to do in 
the app to make it more resilient to these kinds of issues.

K,

On Monday, March 6, 2017 at 3:21:37 PM UTC, Mike Bayer wrote:
>
> a ROLLBACK is occurring which suggests a different error has occurred 
> and is being swallowed - the transaction can then not continue. Does 
> your production environment have logs which would illustrate other 
> exceptions and reasons for rollbacks prior to this one?   It is possible 
> that something like autoflush on query is causing a flush to fail, 
> something lime that. 
>
>
>
>
>
> On 03/06/2017 08:03 AM, karl.l...@innolabs.uk  wrote: 
> > Hi, I'm having some trouble with sqlalchemy and timestamps 
> > 
> > I have a schema which looks like this 
> > 
> > 
> > class MyTable(Entity): 
> > __tablename__ = "MyTable" 
> > id = Column(Integer, primary_key=True) 
> > tstamp = Column(DateTime, nullable=False) 
> > 
> > 
> > when I run a query such as 
> > 
> > 
> > current_time = datetime.datetime.utcnow() 
> > s = current_time - datetime.timedelta(hours=1) 
> > hour_ago = s.isoformat() 
> > query = session.query(func.count(MyTable)).filter(MyTable > hour_ago) 
> > 
> > I will get the following StatementError - but not on my local testing 
> > (mac os sierra) system, only when testing the system on our live docker 
> > based system (Ubuntu:wily) 
> > 
> > Has anyone come across this issue before? I've tried using a date time 
> > object but that resulted to the same problem so I opted to change to the 
> > iso string. It seems that the timestamp is simply not being passed to 
> > the query statement in the parameters. 
> > 
> > StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect 
> > until invalid transaction is rolled back [SQL: u'SELECT 
> > count(`MyTable`.id) AS count_1 \nFROM `MyTable` \nWHERE `MyTable`.tstamp 
> >> %s'] [parameters: [ 
> > {} 
> > ]] 
> > 
> > Any help would be much appreciated. 
> > 
> > Regards, 
> >  K, 
> > 
> > -- 
> > 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.


Re: [sqlalchemy] Problems with sqlalchemy and timestamps

2017-03-06 Thread Jonathan Vanasco


On Monday, March 6, 2017 at 10:21:37 AM UTC-5, Mike Bayer wrote:
>
> a ROLLBACK is occurring which suggests a different error has occurred 
> and is being swallowed - the transaction can then not continue. Does 
> your production environment have logs which would illustrate other 
> exceptions and reasons for rollbacks prior to this one?   It is possible 
> that something like autoflush on query is causing a flush to fail, 
> something lime that. 
>

Can you also share your connection strings for each environment?  You 
should also enable logging on sqlalchemy and the backend server. 

In my experience with situations like this, a certain approach/command/etc 
works on one database but not another -- and that triggers the error.  When 
you look at logs and the connection string , it becomes easy to pinpoint.

-- 
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] Problems with sqlalchemy and timestamps

2017-03-06 Thread mike bayer
a ROLLBACK is occurring which suggests a different error has occurred 
and is being swallowed - the transaction can then not continue. Does 
your production environment have logs which would illustrate other 
exceptions and reasons for rollbacks prior to this one?   It is possible 
that something like autoflush on query is causing a flush to fail, 
something lime that.






On 03/06/2017 08:03 AM, karl.latti...@innolabs.uk wrote:

Hi, I'm having some trouble with sqlalchemy and timestamps

I have a schema which looks like this


class MyTable(Entity):
__tablename__ = "MyTable"
id = Column(Integer, primary_key=True)
tstamp = Column(DateTime, nullable=False)


when I run a query such as


current_time = datetime.datetime.utcnow()
s = current_time - datetime.timedelta(hours=1)
hour_ago = s.isoformat()
query = session.query(func.count(MyTable)).filter(MyTable > hour_ago)

I will get the following StatementError - but not on my local testing
(mac os sierra) system, only when testing the system on our live docker
based system (Ubuntu:wily)

Has anyone come across this issue before? I've tried using a date time
object but that resulted to the same problem so I opted to change to the
iso string. It seems that the timestamp is simply not being passed to
the query statement in the parameters.

StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect
until invalid transaction is rolled back [SQL: u'SELECT
count(`MyTable`.id) AS count_1 \nFROM `MyTable` \nWHERE `MyTable`.tstamp

%s'] [parameters: [

{}
]]

Any help would be much appreciated.

Regards,
 K,

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