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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

psycopg2/extensions.py changes the dictionary it iterates through

#77

Submitted by: Constantin Makshin

The "clean up encodings" loop at the bottom of psycopg2/extensions.py 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\psycopg2__init__.py", line 84, in

import psycopg2.extensions as _ext

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

for k, v in encodings.items():

RuntimeError: dictionary changed size during iteration

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

State: invalid
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • 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 http://www.stickpeople.com/projects/python/win-psycopg/ doesn't have this problem.

    November 22nd, 2011 @ 11:59 AM