Fix datetime microsecond discrepancy issue
All ``POST/PUT`` restFul APIs which returns datetime parameters in the response contains microseconds whereas `GET` APIs ignores microseconds part. After a db object is created, it creates the datetime with microseconds and the subsequent get db calls using the same session object returns microseconds for the datetime fields. This patch fixes this issue by overriding `TimestampMixin` to exclude microseconds part from the datetime fields so that the subsequence get db calls using the same db session object return datetime fields without microseconds. Change-Id: Iff6367757c7c2832bf0c99e09f9c7a97c428d1cc Closes-Bug: #1788883
This commit is contained in:
parent
9649cd28ae
commit
0f8b8c938a
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
from oslo_db.sqlalchemy import models
|
||||
from oslo_utils import timeutils
|
||||
from sqlalchemy import (Column, DateTime, Index, Integer, Enum, String,
|
||||
schema)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
@ -24,7 +25,20 @@ from sqlalchemy import ForeignKey, Boolean, Text
|
|||
BASE = declarative_base()
|
||||
|
||||
|
||||
class MasakariAPIBase(models.TimestampMixin, models.ModelBase):
|
||||
class MasakariTimestampMixin(object):
|
||||
# Note(tpatil): timeutils.utcnow() method return microseconds part but db
|
||||
# doesn't store it because of which subsequent calls to get resources
|
||||
# from the same db session object instance doesn't return microsecond for
|
||||
# datetime fields. To avoid this discrepancy, removed microseconds from
|
||||
# datetime fields so that there is no need to remove it for create/update
|
||||
# cases in the respective versioned objects.
|
||||
created_at = Column(DateTime, default=lambda: timeutils.utcnow().replace(
|
||||
microsecond=0))
|
||||
updated_at = Column(DateTime, onupdate=lambda: timeutils.utcnow().replace(
|
||||
microsecond=0))
|
||||
|
||||
|
||||
class MasakariAPIBase(MasakariTimestampMixin, models.ModelBase):
|
||||
"""Base class for MasakariAPIBase Models."""
|
||||
|
||||
metadata = None
|
||||
|
|
Loading…
Reference in New Issue