Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Equality does not work for psycopg2._psycopg.datetime objects.

#136
>>> ts = 1351283379.10619
>>> psycopg2.DateFromTicks(ts) == psycopg2.DateFromTicks(ts)
False

Reported by Kevin Warrick · October 27th, 2012 @ 12:35 AM

State: invalid
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from new to invalid

    From the documentation, which is copied from the dbapi

    psycopg2.DateFromTicks(ticks)
      This function constructs an object holding a date value from the given ticks value
      (number of seconds since the epoch; see the documentation of the standard Python
      time module for details).
    

    The object returned is a wrapper for a date object:

    In [8]: x = psycopg2.DateFromTicks(1351283379.10619)
    
    In [9]: x
    Out[9]: <psycopg2._psycopg.datetime object at 0x94ab8cc>
    
    In [10]: x.adapted
    Out[10]: datetime.date(2012, 10, 26)
    

    psycopg returns adapters in several places, which are only used to pass data to the database. We don't give any of these adapter the semantics of the wrapped object (comparability, ordering etc). Please extract the object you need to work with from the wrapper and use it as you need. I will add to the documentation the fact that it can be reached through the adapted attribute.

    October 27th, 2012 @ 12:43 PM