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

Flask-Fixtures will parse string containing numbers as datetime #28

Open jmgnc opened 7 years ago

jmgnc commented 7 years ago

I have a simple database, and tried to load a fixture: [ { "model": "app.models.Devices", "records": [ { "uuid": "1", "name": "Agent" } ] }]

it tries to parse the uuid as a datetime object. It should not. If I change the value of uuid to "a1" then it is properly a string.

The model is: class Devices(db.Model): tablename = 'devices' name = Column(String, nullable=False) uuid = Column(String, primary_key=True, nullable=False)

jmgnc commented 7 years ago

the parameters will be: [parameters: {'name': 'Agent', 'uuid': datetime.datetime(2016, 10, 1, 0, 0)}]

yaoelvon commented 7 years ago

I encountered the same problem, had to precede the number with letters. Can you tell me why?

s7anley commented 7 years ago

Unfortunately JSONLoader is trying to automatically parse everything into datetime in flask_fixtures/loaders.py:59. I didn't find way so far , how to use custom JSONLoader instead of provided one as workaround.

s7anley commented 7 years ago

You can try my PR https://github.com/croach/Flask-Fixtures/pull/32 which allows you to disable parsing. Hopefully @croach will merged it soon.

fangli commented 7 years ago

+1, same issue

lucious7 commented 6 years ago

+1

Same problem. It only happens if you have dateutil installed.

@s7anley Your PR is from 2016, is it going to be merged yet? Anyway, it fixes the problem only partially. In my case I have string fields representing dates and numbers in the same json.

The workaround I found is to use number in those fields, instead of string representing numbers (as they really are in the database). I'll try to come up with yet another solution for this.

lucious7 commented 6 years ago

Also, if you use yaml instead of json it will work fine.