Re: [sqlalchemy] Unable to store datetime.datetime.max using SQLAlchemy==0.8.1 with the mysql-python==1.2.4 driver

2013-06-27 Thread Pelle Almquist
Thanks for the quick response!

On Wednesday, June 26, 2013 5:30:00 PM UTC+2, Michael Bayer wrote:


 On Jun 26, 2013, at 10:18 AM, Pelle Almquist pe...@wrapp.comjavascript: 
 wrote: 

  Hi, 
  not sure if I should post this issue here or if its a mysql-python one 
 but perhaps someone with better knowledge can help me figure that out? 
  A more pretty print version of this issue is available here: 
 http://stackoverflow.com/questions/17315422/unable-to-store-datetime-datetime-max-using-sqlalchemy-0-8-1-with-the-mysql-pyt
  
  
  I've noticed a change in behavior for storing datetime.datetime.max via 
 `SQLAlchemy==SQLAlchemy==0.8.1` and going from `mysql-python==1.2.3` to 
 `mysql-python==1.2.4`. By only changing the driver from 1.2.3 to 1.2.4 I go 
 from being able to store to being unable to store it. 
  
  Where do I turn to for help in this matter? SQLAlchemy or mysql-python? 
 Is this expected behaviour or a bug or do I have a bad setup? I fear that a 
 change like this will break a lot of systems out there. 

 Well it seems like MySQL-python doesn't like trying to store a date with 
 the year  here, it probably changed something about how it renders 
 dates.  So yeah you'd need to take it up with Python-MySQL. 


I've created a GitHub issue for those 
interested https://github.com/farcepest/MySQLdb1/issues/21
 


 I would note that there are some good alternatives to MySQL-Python on the 
 scene now, there's OurSQL, PyMySQL, and MySQL-connector-python seems to be 
 working decently now, in case that helps. 

 Interesting :) 

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] Unable to store datetime.datetime.max using SQLAlchemy==0.8.1 with the mysql-python==1.2.4 driver

2013-06-26 Thread Pelle Almquist
Hi,
not sure if I should post this issue here or if its a mysql-python one but 
perhaps someone with better knowledge can help me figure that out?
A more pretty print version of this issue is available 
here: 
http://stackoverflow.com/questions/17315422/unable-to-store-datetime-datetime-max-using-sqlalchemy-0-8-1-with-the-mysql-pyt

I've noticed a change in behavior for storing datetime.datetime.max via 
`SQLAlchemy==SQLAlchemy==0.8.1` and going from `mysql-python==1.2.3` to 
`mysql-python==1.2.4`. By only changing the driver from 1.2.3 to 1.2.4 I go 
from being able to store to being unable to store it.

Where do I turn to for help in this matter? SQLAlchemy or mysql-python? Is 
this expected behaviour or a bug or do I have a bad setup? I fear that a 
change like this will break a lot of systems out there.

This is my SQLAlchemy setup:

from sqlalchemy import create_engine, Integer, DateTime, Column
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

engine = create_engine('mysql://root@localhost/test_database', 
echo=True)
Base = declarative_base()

class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
age = Column(DateTime, default=datetime.max)

Base.metadata.create_all(engine)
session = sessionmaker(bind=engine)()
u = User()
session.add(u)
session.commit()

I also have a virtualenv called test. This is what happens when I run the 
code above.

(test)➜  ~  pip install MySQL-python==1.2.3
(test)➜  ~  python test.py
2013-06-26 10:29:18,885 INFO sqlalchemy.engine.base.Engine SELECT 
DATABASE()
2013-06-26 10:29:18,885 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:29:18,887 INFO sqlalchemy.engine.base.Engine SHOW 
VARIABLES LIKE 'character_set%%'
2013-06-26 10:29:18,887 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:29:18,891 INFO sqlalchemy.engine.base.Engine SHOW 
VARIABLES LIKE 'sql_mode'
2013-06-26 10:29:18,891 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:29:18,896 INFO sqlalchemy.engine.base.Engine DESCRIBE 
`users`
2013-06-26 10:29:18,896 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:29:18,904 INFO sqlalchemy.engine.base.Engine BEGIN 
(implicit)
2013-06-26 10:29:18,905 INFO sqlalchemy.engine.base.Engine INSERT INTO 
users (age) VALUES (%s)
2013-06-26 10:29:18,905 INFO sqlalchemy.engine.base.Engine 
(datetime.datetime(, 12, 31, 23, 59, 59, 99),)
2013-06-26 10:29:18,908 INFO sqlalchemy.engine.base.Engine COMMIT

And the database (test_database) looks like this:

mysql select * from users;
++-+
| id | age |
++-+
|  1 | -12-31 23:59:59 |
++-+
1 row in set (0.00 sec)

This is my expected result so nothing strange here.

However, by simply switching the driver to mysql-python==1.2.4 I get this 
result.

(test)➜  ~  pip install MySQL-python==1.2.4
(test)➜  ~  python test.py
2013-06-26 10:33:39,544 INFO sqlalchemy.engine.base.Engine SELECT 
DATABASE()
2013-06-26 10:33:39,544 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:33:39,546 INFO sqlalchemy.engine.base.Engine SHOW 
VARIABLES LIKE 'character_set%%'
2013-06-26 10:33:39,546 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:33:39,546 INFO sqlalchemy.engine.base.Engine SHOW 
VARIABLES LIKE 'sql_mode'
2013-06-26 10:33:39,546 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:33:39,547 INFO sqlalchemy.engine.base.Engine DESCRIBE 
`users`
2013-06-26 10:33:39,547 INFO sqlalchemy.engine.base.Engine ()
2013-06-26 10:33:39,551 INFO sqlalchemy.engine.base.Engine BEGIN 
(implicit)
2013-06-26 10:33:39,552 INFO sqlalchemy.engine.base.Engine INSERT INTO 
users (age) VALUES (%s)
2013-06-26 10:33:39,552 INFO sqlalchemy.engine.base.Engine 
(datetime.datetime(, 12, 31, 23, 59, 59, 99),)

/Users/pelle/.virtualenvs/test/lib/python2.7/site-packages/sqlalchemy/engine/default.py:324:
 
Warning: Datetime function: datetime field overflow
  cursor.execute(statement, parameters)

/Users/pelle/.virtualenvs/test/lib/python2.7/site-packages/sqlalchemy/engine/default.py:324:
 
Warning: Out of range value for column 'age' at row 1
  cursor.execute(statement, parameters)
2013-06-26 10:33:39,553 INFO sqlalchemy.engine.base.Engine COMMIT

And the database looks like this.

mysql select * from users;
++-+
| id | age |
++-+
|  1 | -00-00 00:00:00 |
++-+
1 row in set (0.00 sec)

So now all of the sudden I receive a warning `Warning: Datetime function: 
datetime field overflow` and I end up with a nullable value in my database.


-- 
You received this message because you are subscribed to the Google Groups 

Re: [sqlalchemy] Unable to store datetime.datetime.max using SQLAlchemy==0.8.1 with the mysql-python==1.2.4 driver

2013-06-26 Thread Michael Bayer

On Jun 26, 2013, at 10:18 AM, Pelle Almquist pe...@wrapp.com wrote:

 Hi,
 not sure if I should post this issue here or if its a mysql-python one but 
 perhaps someone with better knowledge can help me figure that out?
 A more pretty print version of this issue is available here: 
 http://stackoverflow.com/questions/17315422/unable-to-store-datetime-datetime-max-using-sqlalchemy-0-8-1-with-the-mysql-pyt
 
 I've noticed a change in behavior for storing datetime.datetime.max via 
 `SQLAlchemy==SQLAlchemy==0.8.1` and going from `mysql-python==1.2.3` to 
 `mysql-python==1.2.4`. By only changing the driver from 1.2.3 to 1.2.4 I go 
 from being able to store to being unable to store it.
 
 Where do I turn to for help in this matter? SQLAlchemy or mysql-python? Is 
 this expected behaviour or a bug or do I have a bad setup? I fear that a 
 change like this will break a lot of systems out there.

Well it seems like MySQL-python doesn't like trying to store a date with the 
year  here, it probably changed something about how it renders dates.  So 
yeah you'd need to take it up with Python-MySQL.

I would note that there are some good alternatives to MySQL-Python on the scene 
now, there's OurSQL, PyMySQL, and MySQL-connector-python seems to be working 
decently now, in case that helps.


-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.