croach / Flask-Fixtures

A simple library for adding database fixtures for unit tests using nothing but JSON or YAML.
MIT License
63 stars 30 forks source link

SQLite gotcha #10

Closed greedo closed 9 years ago

greedo commented 9 years ago

If you try to set a SQLAlchemy DateTime value using SQLite as the backing database, you will get

sqlalchemy.exc.StatementError
StatementError: SQLite Date type only accepts Python date objects as input.

Since you cannot really import datetime and set this in the json directly it be handled as the object is created

import datetime
created = datetime.utcnow()
cod = Code(created=created)
db.session.add(cod)
db.session.commit()

Or using a separate setter function.

Again this is a gotcha with SQLite that is up to you to either warn people about or provide a way for them to be set.

croach commented 9 years ago

Hi greedo,

Thanks a bunch for filing the issue. I hadn't noticed the problem myself because I'm using YAML for all of my fixtures files, and it has the ability to markup things like datetimes (see the example below).

start_time: !!timestamp 2013-03-07T10:30:00-08:00
end_time: !!timestamp 2013-03-07T11:30:00-08:00

I don't think this is a hard problem to solve, I believe I just need to write up a custom decoder that I use when I load the JSON. I'll get to it as soon as I can, but in the meantime, maybe you should try YAML. I tend to prefer it myself. Personally, I think it's easier to read than JSON, and I love the fact that I can comment all of my fixtures.

croach commented 9 years ago

Fixed by ca780e3