Flask-Fixtures icon indicating copy to clipboard operation
Flask-Fixtures copied to clipboard

Flask-Fixtures will parse string containing numbers as datetime

Open jmgnc opened this issue 8 years ago • 7 comments

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 avatar Oct 18 '16 01:10 jmgnc

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

jmgnc avatar Oct 18 '16 01:10 jmgnc

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

yaoelvon avatar Mar 01 '17 02:03 yaoelvon

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 avatar Apr 21 '17 05:04 s7anley

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.

s7anley avatar Apr 25 '17 04:04 s7anley

+1, same issue

fangli avatar Aug 09 '17 04:08 fangli

+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 avatar Mar 22 '18 14:03 lucious7

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

lucious7 avatar Mar 23 '18 14:03 lucious7