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

Error with null dates #181

Closed
DavidePastore opened this issue Feb 27, 2014 · 8 comments
Closed

Error with null dates #181

DavidePastore opened this issue Feb 27, 2014 · 8 comments

Comments

@DavidePastore
Copy link

I have a database with 'birth_date' column, which can be NULL or a date.

If I use plain 'echo' to output birth_day, it works in either case - as null and as a date.

If however I'm using Twig as a template engine and accessing birthday through Twig, it works ONLY when there is a date. If there is NULL, then application crashes and browser gives me back ERR_EMPTY_RESPONSE. Nothing more.

I'm pretty sure the problem occurs somewhere in the ORM, but I can't figure out how to solve it. I'd like to have just and empty string outputed in Twig if there's a NULL in db.

This isn't a problem of Twig because if I pass to it a null value, it simply doesn't print it.

@tag
Copy link
Contributor

tag commented Feb 27, 2014

NULL and empty string are different, so this wouldn't be appropriate, I think.

One way to handle it is to add NOT NULL DEFAULT '' to your column definition in your database, so that you prevent NULLs on the data side.

@DavidePastore
Copy link
Author

@tag: The problem is that the field is of DATE type. If I set it to a NOT NULL DEFAULT '' it will set to the 00:00:00 value.

@treffynnon
Copy link
Collaborator

There won't be any casting on NULL to an empty string for the reasons @tag
states.

I am not sure why there is an issue with Twig, but a number of users have
reported it as being a recursive call triggering it.

Unfortunately I have never experienced this bug despite using both Idiorm
and Twig in projects so I have been unable to observe it.

@DavidePastore
Copy link
Author

I'll try to create a simple project where the problem arises.

@tag
Copy link
Contributor

tag commented Feb 27, 2014

I use Twig as well, and for various design reasons haven't encountered this error. Off the top of my head, I wonder whether a custom Twig filter might help with the issue as well.

@DavidePastore
Copy link
Author

This is a thread where there is the same problem.

This solution is a little forced.

The real problem is that the application crashes when you try to access to that field via twig. Even a simple check to see if the variable is defined leads to a crash.

I created this project to reproduce the same issue. Check it and the instructions in README.md.

@nicolas-t
Copy link

Hi,

Same issue here :(

@treffynnon
Copy link
Collaborator

Thank you for all the effort you have put in here. Does anyone have any time to put together a pull request that fixes this issue? I am struggling to find the time to test this out.

treffynnon added a commit that referenced this issue Jun 20, 2014
offsetExists() should return true for null values, resolves #181
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

4 participants