[openstack-dev] [oslo] question about oslo_utils and oslo_versonedobjects

zengchen chenzeng765 at 163.com
Tue Mar 7 06:34:44 UTC 2017

Hi, guys:
     I find a non-coincidence definition in Oslo, 

     oslo_utils.timeutils.utcnow is defined like this:
         def utcnow(with_timezone=False):

    oslo_versonedobjects.fields.DateTimeField is defined like this
class DateTimeField(AutoTypedField): def __init__(self, tzinfo_aware=True, **kwargs):

    a = utcnow()
    class ABC(VersionedObject):
        fields = {
            created_at = fields.DateTimeField()
    b = ABC(), and fill it by db record.

    If I compare a and b.created_at,  it will raise an exception like this:
       'TypeError: can't compare offset-naive and offset-aware datetimes'
    because a's value is like this:
        datetime.datetime(2017, 3, 7, 2, 34, 50, 859002)
    b.created_at 's value is like this:
         datetime.datetime(2017, 3, 7, 2, 35, 27, 400786, tzinfo=<iso8601.Utc>)

   Can these two kinds of time's definition be coincident? For example:
       def utcnow(with_timezone=False):

       class DateTimeField(AutoTypedField):
            def __init__(self, tzinfo_aware=False, **kwargs):

best wishes
zeng chen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20170307/8c160657/attachment.html>

More information about the OpenStack-dev mailing list