Flask-Fixtures
Flask-Fixtures copied to clipboard
Flask-Fixtures will parse string containing numbers as datetime
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)
the parameters will be: [parameters: {'name': 'Agent', 'uuid': datetime.datetime(2016, 10, 1, 0, 0)}]
I encountered the same problem, had to precede the number with letters. Can you tell me why?
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.
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.
+1, same issue
+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.
Also, if you use yaml instead of json it will work fine.