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

Removing zeroed dates #16

Open
wants to merge 2 commits into
base: master/elche
Choose a base branch
from

Conversation

Seb-C
Copy link

@Seb-C Seb-C commented Apr 21, 2016

This removes the default dates 0000-00-00 00:00:00 and replaces it with NULL, since 0000-00-00 it's not a valid date NOR recognized by any API.

`<?= $model['column_prefix'].$field['column_name'] ?>` timestamp NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use the explicit syntax NULL DEFAULT NULL instead of the implicit syntax NULL for readability.

@Meroje
Copy link

Meroje commented Apr 21, 2016

👍 the zero date is also refused by strict mode

@shaoshiva
Copy link
Collaborator

This will break all the features that compare dates lesser than something.

Take this query for example :

SELECT * FROM `test` WHERE date < '2016-04-22'

It will match the rows with a date whose value is 0000-00-00 00:00:00 but not those whose value is NULL.

@Seb-C Seb-C force-pushed the removeZeroedDates branch from 16ebd79 to 73eaf45 Compare April 22, 2016 07:13
@Seb-C
Copy link
Author

Seb-C commented Apr 22, 2016

I don't think an empty date should be comparable with another. Plus, this can't break existing apps since it will only affect future migrations.

@shaoshiva
Copy link
Collaborator

shaoshiva commented Apr 22, 2016

You PR affect the fields used by the updated/created observer, so there may be features that rely on it and that could make comparison in a query.

I'm just saying that this could have side effects, nothing else.

@Meroje
Copy link

Meroje commented Apr 22, 2016

No breaking change though (and the behaviour you mention will set valid dates).

I could find code that has to check for zeroed dates in addition to null, but nothing expecting valid work from it

@shaoshiva
Copy link
Collaborator

Ok, here is an example.

I developped a website using the app wizard, dates fields were created with a default empty value, then I developped a behaviour to find all the items that were imported before :

$item->find_imported_before();

The method executes a query with a condition on the "imported_at" field :

$this->query(array(
  'where' => array(
    array('imported_at', '<', $this->imported_at),
  )
));

This will return all the items with a date lesser than the date on the current item and thoses with an empty date, that's how mysql works.

Then you patch the App Wizard with this PR. Now If I want to create a new application with a model that implements this behaviour, it won't work as expected, because dates with NULL values won't be returned.

Breaking change.

@Meroje
Copy link

Meroje commented Apr 26, 2016

Your behavior is confusing, expect bugs. I would expect items without a valid import date to not have been imported, thus I also do not expect to find them with find_imported_before()

@Seb-C
Copy link
Author

Seb-C commented Apr 26, 2016

This may break future developments using the behaviour, but it won't break already running apps.
Plus, this will allow you to further improve the code since this kind of comparison without any checks is dangerous and semantically wrong.
And this kind of code seems unlikely to me since it won't work with migrations created without the app wizard nor with many databases.

@Meroje
Copy link

Meroje commented Apr 26, 2016

I understand the generated app is breaking compatibility now, but there is no issue with that right ?

@shaoshiva
Copy link
Collaborator

👍 if published in a major release and/or a note that indicates this change

@Meroje
Copy link

Meroje commented Apr 28, 2016

👍

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

Successfully merging this pull request may close these issues.

3 participants