malthe / pq

A PostgreSQL job queueing system
376 stars 41 forks source link

Fix ValueError('Encountered duplicate field name: timezone #24

Closed xq5he closed 7 years ago

xq5he commented 7 years ago

When using NamedTupleCursor in psycopg2, the ValueError is thrown because enqueued_at AT TIME ZONE 'utc', schedule_at AT TIME ZONE 'utc'and expected_at AT TIME ZONE 'utc'have same alias which is timezone


    for task in pq[queue]:
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/pq/__init__.py", line 81, in __next__
    return self.queue.get(timeout=self.timeout)
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/pq/__init__.py", line 176, in get
    cursor, block
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/pq/utils.py", line 76, in wrapper
    return f(self, cursor, *args[arg_count:])
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/pq/__init__.py", line 323, in _pull_item
    row = cursor.fetchone()
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/psycopg2/extras.py", line 331, in fetchone
    nt = self.Record = self._make_nt()
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/envs/reportr/lib/python3.6/site-packages/psycopg2/extras.py", line 371, in _make_nt
    return namedtuple("Record", [d[0] for d in self.description or ()])
  File "/Users/meijunzhu/.pyenv/versions/3.6.1/lib/python3.6/collections/__init__.py", line 413, in namedtuple
    raise ValueError('Encountered duplicate field name: %r' % name)
ValueError: Encountered duplicate field name: 'timezone'```
stas commented 7 years ago

@xq5he thanks for the report. Do you think you can provide a test case for this issue?

xq5he commented 7 years ago

@stas Test is added.

malthe commented 7 years ago

It would be good to have a change entry in the change log.

Edit: Now committed in c7e2545867e11811e6fd241d1bc311b334eb4e76.