This project is archived and is in readonly mode.

#77 ✓invalid
Psycopg website

psycopg2/ changes the dictionary it iterates through

Reported by Psycopg website | November 20th, 2011 @ 08:13 PM

Submitted by: Constantin Makshin

The "clean up encodings" loop at the bottom of psycopg2/ changes the dictionary it iterates through, causing a RuntimeError in Python 3:

Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import psycopg2 Traceback (most recent call last):
File "", line 1, in File "C:\Program Files\Python\lib\site-packages\", line 84, in

import psycopg2.extensions as _ext

File "C:\Program Files\Python\lib\site-packages\psycopg2\", line 157, in

for k, v in encodings.items():

RuntimeError: dictionary changed size during iteration

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo November 22nd, 2011 @ 11:59 AM

    • State changed from “new” to “invalid”

    You are somehow using psycopg on python 3 that has not been passed through 2to3.

    2to3 correctly converts the line to an idiom non replacing inplace, specifically I get on Python 3.2:

    @@ -154,10 +154,10 @@
     # When the encoding is set its name is cleaned up from - and _ and turned
     # uppercase, so an encoding not respecting these rules wouldn't be found in the
     # encodings keys and would raise an exception with the unicode typecaster
    -for k, v in encodings.items():
    +for k, v in list(encodings.items()):
         k = k.replace('_', '').replace('-', '').upper()
         encodings[k] = v
     del k, v

    please see the Makefile to know how to convert psycopg from Python 2 to 3. Also note that Jason's package at doesn't have this problem.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="">the new tracker</a>.
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins