Last night, I upgrade to the latest date module from CVS for branch DRUPAL-5--2.
Then all my calendar views broke! And they broke bad... the calendar was suddenly empty.
When I reverted to a backup from Apr 7 18:29 (Chicago), everything cleared up and my calendar views worked again.
It's a Sunday, so I really don't want to spend the day figuring out why the latest CVS checkout broke my views. I'll get on it tomorrow.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | date2.filter.patch | 744 bytes | dopry |
| #14 | devel.escaped_view_query.patch | 815 bytes | dopry |
| #4 | views-mysql-fix.patch | 904 bytes | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) commentedNobody else is having trouble with date fields in their views?
The field works fine in my content. The date can be edited, saved, created. However, the queries that views generates are not retrieving any nodes.
Here's a query generated by the calendar view with the latest version of Date module (DRUPAL-5--2):
Here's the query generated by the same view, same version after I reverted to an earlier version of Date module (from April 7):
Comment #2
karens commentedThis is not a Date problem, this is a Calendar problem. The Calendar module needs to be updated for a recent change in the Date API.
Comment #3
Anonymous (not verified) commentedAll views on my development site that use date fields are broken. Not just calendar views. Sorry, I'm just now really getting into this problem.. my earlier reports are shallow with facts.
Comment #4
Anonymous (not verified) commentedYup. it's definitely a date bug, because I fixed it! It was quite a puzzler, that's for sure.
There's also a likely fix for a bug which I didn't encounter. It just screamed "typo" of the sort that caused this bug. Perhaps there's some funny escaping going on with a text editor somewhere?
Comment #5
karens commentedNo, that escaping is needed to keep the query from being mangled by Drupal's query builder. I still need to make some changes on the Calendar module side to use the new code, and it's possible there are other date queries that still need work. The date field filters now work correctly with that code, but I haven't made my way to every possible place that might be affected.
When you say 'all views are broken', I need more information about Date-only views (not Calendar views) that are still broken. I know the Calendar Views are broken and plan to work on them next.
Comment #6
Anonymous (not verified) commentedKarenS,
I think there were too many % in the STR_TO_DATE function for MySQL. After passing through the query builder, the output would have been %%d when we need it to be just %d. That made the field always NULL in the query.
The patch definitely fixes the problem I was having. Is it wrong?
Comment #7
karens commentedThe current code produces exactly the right result when creating views date filters and your patch would break them.
You haven't given me any information on what queries you're seeing that are broken with the current code and fixed by your patch so I have no way to do anything else with this. I need something reproducable -- like a view export with a cut and paste of the query that it creates that is wrong. Plus it may be that this is system-related, so info on what version of PHP and mysql you're using might help.
Comment #8
Anonymous (not verified) commentedKarenS,
The queries are here. Here's the query built by an unpatched Date_api_sql.inc:
And here's the query generated with my patch applied:
The key difference is in STR_TO_DATE. The unpatched date makes a query that has an extra percent sign, which is coming from the quadruple escaping of the 'd' placeholder.
Comment #9
karens commentedI need to know where that query is getting constructed in order to do anything with this. Is it coming from a View, and which one, and how is the view set up? The query is created by a handler and I need to know which handler is being used. The handlers I am testing are producing the right result. Apparently you are using a handler that isn't, so I have to know where this is coming from.
Comment #10
Anonymous (not verified) commentedKarenS.
All of my views with date fields are affected. If I bring Calendar into the situation, it may just confuse things. Here is a view that I'm using to display valid items of a particular type. Validity is determined by comparing a date field to now(). I apologize if I'm giving you too much information, but I am not sure how to find out which handler I am using.
With my patch, the query produced (for the page view) is:
However the latest checkout makes this query:
%Y-%m-%%dT%T for a date format looks wrong to me. It has an extra %.
I'm using PHP 5.2, MySQL 5... standard Debian stable packages.
Comment #11
karens commentedFixed in latest commit. Thanks!
Comment #12
karens commentedMarked wrong issue. I can't reproduce this though, the query works fine for me with the code as-is, so this needs more investigation.
Comment #13
Anonymous (not verified) commentedOk. Please let me know what I can do to continue to diagnose the problem.
Comment #14
dopry commented@KarenS,
The latest DRUPAL-5--2 HEAD seems to have a double escaping for the STR_TO_DATE....
here is the view so you can see how the view is configured, it does use calendar, but calendar only provides an output handler for views as far as I can tell...
Where clause before patch:
ADDTIME(STR_TO_DATE(node_data_field_start.field_start_value, '%Y-%m-%%%%dT%T'), SEC_TO_TIME(28800)) <='2008-01-01 23:59:59'))
Escaped where clause before patch*:
ADDTIME(STR_TO_DATE(node_data_field_start.field_start_value, '%Y-%m-%%dT%T'), SEC_TO_TIME(28800)) <='2008-01-01 23:59:59'))
Mysql Says:
Where clause after patch:
ADDTIME(STR_TO_DATE(node_data_field_start.field_start_value, '%Y-%m-%%dT%T'), SEC_TO_TIME(28800)) <='2008-01-01 23:59:59'))
Escaped where clause after patch*:
ADDTIME(STR_TO_DATE(node_data_field_start.field_start_value, '%Y-%m-%dT%T'), SEC_TO_TIME(28800)) <='2008-01-01 23:59:59'))
Mysql Says:
* I've also attached the patch I use on devel to see escaped queries. DRUPAL-5
Comment #15
karens commentedThe problem is that on my system I need the extra escaping or the values get mangled -- '%d' becomes '0' by the time it gets to MYSQL. I'm trying to figure out exactly where and why that is happening.
Comment #16
dopry commenteddb_rewrite_sql/hook_rewrite_sql would be a good place to look for such insanity... at least its a pattern to start with.
Comment #17
BrianKlinger commentedHello, KarenS. I was glancing through this and noticed you mentioning your trouble with %d. There was a problem with this in Views that Merlinofchaos created a patch for and that took care of the views (the issue surfaced somewhere in the 5.4-5.7 upgrades - I don't remember for sure which one it was). I don't know if this is the same thing or if this helps you at all, but here's the link to the issue, patch, and subsequent comments/discussion. http://drupal.org/node/165611
Comment #18
karens commentedFound the culprit, now I need to think of the best solution.
The problem is there is a Views function, _views_replace_args(). _views_replace_args() runs the Views query through _db_query_callback(), and it gets run through _db_query_callback() again in db_query(). So any view that triggers that Views function needs double escaping to work right. If I keep that Views function from doing its replacements, my queries work correctly with the normal escaping. If you create SQL outside of Views, the double escaping will not work right, of course, and there may be some Views that don't trigger that function and the double escaping won't work right there, either, so I need to find a way to make the SQL work right whether or not it runs through that function.
Comment #19
karens commentedI've come up with a possible solution for this using Views substitutions that will be fixed by my filter fix in http://drupal.org/node/247752. I'm going to swap out all '%%d' values in the pre_query and swap them back in using Views substitutions. That seems to get them safely through Views processing.
Comment #20
karens commentedMore info on this problem. The problems with the escaping come from a Views bug that was fixed in January but the fix is not in the official release. So the double escaping was needed for this to work with the latest official Views release, but it broke in the latest Views dev version. I was testing with the latest official release, so I needed the double escaping, when I switch to the dev version things work fine without it.
The good news is that the bug is fixed and my work-around isn't needed so long as you are using the dev version of Views.
Comment #21
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.