The created_at and updated_at filters don't work with a postgresql db

Bug #1588007 reported by Castulo J. Martinez
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Glance
New
Undecided
Unassigned
Nominated for Mitaka by Kairat Kushaev

Bug Description

When listing images, several optional parameters can be used to filter the list of images retrieved by the API, these parameters can be found in the API documentation (http://developer.openstack.org/api-ref-image-v2.html#listImages-v2). As part of those filters, there are two that can be used with date time stamps in the ISO 8601 DateTime notation, these are the created_at and updated_at parameters.

These created_at and updated_at parameters can be used in the following two ways:

 - Without specifying an operator (which defaults to an eq operator)
   e.g. /v2/images?created_at=2016-04-18T21:38:55Z
   Note: This is currently not working, see bug https://bugs.launchpad.net/glance/+bug/1584415

 - With an operator (using one of these: eq, new, lt, lte, gt, gte)
   e.g. /v2/images?created_at=lte:2016-04-18T21:38:55Z

This works as documented when run in an OpenStack environment that has the default backend DataBase of Mysql, but if the environment has a Postgresql database the created_at and updated_at filters always return empty lists even when the filter criteria matches existing images.

Steps to reproduce:

1) Install a devstack environment with the default db backend (mysql).
2) Try listing the images using the created_at or updated_at parameters, using an operator and using the DateTime stamp of an existing image. Like this: /v2/images?created_at=lte:2016-04-18T21:38:55Z.

Expected Results: Glance API should return a list with 1 or more images that match the filter criteria.

3) Install a devstack environment with the postgresql DB backend (https://github.com/openstack-dev/devstack/blob/master/doc/source/configuration.rst#database-backend).
4) Try listing the images again using the same API call used in step 2 against the new environment.

Expected Results: Glance API should work the same as with the mysql DB returning a list of 1 or more images that match the filter criteria.

Actual Results: An empty list is always returned, even when the filter matches existing images.

Extra note: You can also reproduce this bug using the parameters without using an operator but you would need to use the patch https://review.openstack.org/#/c/319682/ that is currently in review.

Revision history for this message
Castulo J. Martinez (castulo-martinez) wrote :

Now that bug 1584415 (https://bugs.launchpad.net/glance/+bug/1584415) has been closed, looks like it only got fixed for MySQL DB backend.

So as an update for this bug, trying to filter images by using the created_at and updated_at parameters fail when the DB backend is Postgresql regardless of if the date includes an operation or not:

1) Using only date without an operator:
/v2/images?created_at=2016-04-18T21:38:55Z
Results in a 400 Bad Request error: Bad "created_at" query filter format. Use ISO 8601 DateTime notation.

2) Using date plus operator:
/v2/images?created_at=lte:2016-04-18T21:38:55Z
Looks like depending on the operator we get different results:

+ using eq: Doesn't work. Results in an empty list even when there are images that match the criteria.

+ using lt: Seems to be working fine. Lists the images that match only the "less than" condition.

+ using lte: Doesn't work. It only lists the images that match the "less than" condition and ignores the "equal" condition.

+ using gt: Doesn't work. It lists the images that match the "greater than" condition but also the "equal".

+ using gte: Seems to be working fine. It lists the images that match the "greater than" condition and the "equal" condition.

Revision history for this message
Castulo J. Martinez (castulo-martinez) wrote :

Turns out I was using an outdated server for testing this, so just an update about how this is failing when using a postgresql db:

1) Using only date without an operator:
/v2/images?created_at=2016-06-02T15:16:15Z
Results in an empty list even when there are images that match the criteria.

2) Using date plus operator (same results as shown in the previous comment):
/v2/images?created_at=lte:2016-04-18T21:38:55Z
Looks like depending on the operator we get different results:

+ using eq: Doesn't work.
Results in an empty list even when there are images that match the criteria.

+ using lt: Works fine.
Lists the images that match only the "less than" condition.

+ using lte: Doesn't work.
It only lists the images that match the "less than" condition and ignores the "equal" condition.

+ using gt: Doesn't work.
It lists the images that match the "greater than" condition but also the "equal".

+ using gte: Works fine.
It lists the images that match the "greater than" condition and the "equal" condition.

+ using neq: Doesn't work.
Lists everything.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.