New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timedelta not supported when using pymysql #190
Comments
Thanks, should be fixed now |
I tried to make tests for it, but apart from really telling the code where my mysql instance is, I wasn't quickly able to create a test. -edit- Thanks for the fix! |
Hi @mikkiweesenaar, The usually convenient way to do the test setup is:
Here is an example of doing this with unittest: from contextlib import closing
import unittest
from pony.orm import *
# Somewhere in the project
def declare_entities(db):
class Author(db.Entity):
name = Required(str)
books = Set('Book')
class Book(db.Entity):
title = Required(str)
author = Required(Author)
# Then in tests:
class DbFixture(object):
db_name = 'test_db'
CONNECTION = {
'host': "localhost",
'user': "ponytest",
'passwd': "ponytest",
}
@classmethod
def setUpClass(cls):
from pony.orm.dbproviders.mysql import mysql_module
with closing(mysql_module.connect(**cls.CONNECTION).cursor()) as c:
try:
c.execute('use sys')
c.execute('drop database %s' % cls.db_name)
except mysql_module.DatabaseError as exc:
print('Did not drop %s: %s' % (cls.db_name, exc))
c.execute('create database %s' % cls.db_name)
c.execute('use %s' % cls.db_name)
cls.db = Database('mysql', db=cls.db_name, **cls.CONNECTION)
return cls.db
@db_session
def tearDown(self):
for entity in db.entities.values():
delete(i for i in entity)
class MyTest(DbFixture, unittest.TestCase):
@classmethod
def setUpClass(cls):
global db
db = DbFixture.setUpClass()
declare_entities(db)
db.generate_mapping(create_tables=True)
@db_session
def setUp(self):
Rowling = db.Author(name='J. K. Rowling')
db.Book(title='Harry Potter', author=Rowling)
@db_session
def test(self):
self.assertEqual(
get(b.title for a in db.Author for b in a.books), 'Harry Potter'
)
test2 = test # checking that teardown works Another option is to create new database for every test, which is slower. |
Starting with this release Pony ORM is release under the Apache License, Version 2.0. # New features * Added getattr() support in queries: https://docs.ponyorm.com/api_reference.html#getattr # Backward incompatible changes * #159: exceptions happened during flush() should not be wrapped with CommitException Before this release an exception that happened in a hook(https://docs.ponyorm.com/api_reference.html#entity-hooks), could be raised in two ways - either wrapped into the CommitException or without wrapping. It depended if the exception happened during the execution of flush() or commit() function on the db_session exit. Now the exception happened inside the hook never will be wrapped into the CommitException. # Bugfixes * #190: Timedelta is not supported when using pymysql
Environment:
MacOSX El Capitan with Python 3.5.1.
python3 -c "import pony; import pymysql; print(pony.__version__, ' & ', pymysql.__version__);"
0.6.6 & 0.7.6.None
Reproduction scenario:
Actual behaviour:
Expected behaviour:
I would have expected that the behaviour would be the same for both sqlite as mysql - that it would just work. I think it is due to
pony/pony/orm/dbproviders/mysql.py
Line 28 in e66d0fe
If I comment this line out, the code works fine.
The text was updated successfully, but these errors were encountered: