Skip to content
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

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

Open
jmgnc opened this issue Oct 18, 2016 · 7 comments
Open

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

jmgnc opened this issue Oct 18, 2016 · 7 comments

Comments

@jmgnc
Copy link

jmgnc commented Oct 18, 2016

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
Copy link
Author

jmgnc commented Oct 18, 2016

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

@yaoelvon
Copy link

yaoelvon commented Mar 1, 2017

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

@s7anley
Copy link

s7anley commented Apr 21, 2017

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
Copy link

s7anley commented Apr 25, 2017

You can try my PR #32 which allows you to disable parsing. Hopefully @croach will merged it soon.

@fangli
Copy link

fangli commented Aug 9, 2017

+1, same issue

@lucious7
Copy link

+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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants