range:max, date times and pluggableindexes
In Zope 2.3.3 we did this with ZCatalog, on a field index: query['effective_date'] = ['', DateTime.now()] query['effective_date_usage'] = 'range:max' This returns all records where the effective_date is lower than todays date OR the effective_date is an empty string. In Zope 2.5.1, the same code now returns *all* records. It seems like now suddenly comparing dates and an empty string always returns true. Question 1: Is there a way to solve this without having to do two separate queries? Question 2: Is it really true that comparing dates and en empty string returns true, no matter what? If that is the case (which it seems to be) then I think it's a bug, unless somebody as very good arguments. :-) Whaddayousay?
----- Original Message ----- From: "Lennart Regebro" <lennart@torped.se> To: <zope-dev@zope.org> Sent: Thursday, May 02, 2002 10:48 Subject: [Zope-dev] range:max, date times and pluggableindexes
In Zope 2.3.3 we did this with ZCatalog, on a field index:
query['effective_date'] = ['', DateTime.now()] query['effective_date_usage'] = 'range:max'
This returns all records where the effective_date is lower than todays date OR the effective_date is an empty string.
In Zope 2.5.1, the same code now returns *all* records. It seems like now suddenly comparing dates and an empty string always returns true.
Smells like a bug. Maybe try to use record-style parameters instead the usage of old-style parameters (described in the Zope Book). If you can provide a short testcase, please file a collector issue. -aj
Smells like a bug. Maybe try to use record-style parameters instead the usage of old-style parameters (described in the Zope Book).
I did that, and it made no difference. I've also dug some more and tested a lot, and figured out the problem: Strings are always evaluates as larger than numbers. The funnys thing is that something, in the index of Zope 2.3.3 handles this so it behaves more as expected when indexing both empty strings and dates in the same index. The indexing of Zope 2.5.1 doesn't do this. I have two ways of solving this, one that I feel is an ugly hack, and one that I think would be "the right way", and need opinions on these options. The Ugly Hack: Make two separate queries each time I need to talk to indexes with both empty strings and dates, and merge the results. Ugh.... The Right Way: Fix DateTime so that it handles '' as a NULLDATE, and compares correctly with this. Possible None could be used too, but then I need to convert None to '' for displaying. Somthing that could be done with the OptionalDateTime fields discussed for Zope 2.6. I could live with The Ugly Hack if I know this will be fixed The Right Way in Zope 2.6. :-) Best Regards Lennart Regebro Torped Strategi och Kommunikation AB
On Thursday 02 May 2002 10:48 am, Lennart Regebro allegedly wrote:
In Zope 2.3.3 we did this with ZCatalog, on a field index:
query['effective_date'] = ['', DateTime.now()] query['effective_date_usage'] = 'range:max'
This returns all records where the effective_date is lower than todays date OR the effective_date is an empty string.
In Zope 2.5.1, the same code now returns *all* records. It seems like now suddenly comparing dates and an empty string always returns true.
That is a funky way to pass the value when using range:max. I would just pass it bare as in: query['effective_date'] = DateTime() You only need to pass a sequence as your search term if: You want to match on multiple values, you are using "range:min:max", or if you are looking for the empty string (which makes me a tad ill whenever I see it, but...). Otherwise, you can just pass the single value. hth, -Casey
participants (3)
-
Andreas Jung -
Casey Duncan -
Lennart Regebro