Issue #3 resolved

syncdb fails with Postgres

inactivist
created an issue

When I use Janitor with Postgres 8.4.11 and psycopg2 2.4.5, syncdb fails. Removing janitor from the list of installed apps allows syncdb to succeed.

Version info: {{{ $ pip freeze Django==1.3 bleach==1.1.1 django-janitor==0.1.2 html5lib==0.95 psycopg2==2.4.5 wsgiref==0.1.2

$ psql --version psql (PostgreSQL) 8.4.11 contains support for command-line editing

$ cat /etc/issue Ubuntu 11.04 }}}

Steps to reproduce the problem: {{{

Create test environment

virtualenv janitor-test cd janitor-test/ source bin/activate pip install Django==1.3 psycopg2 django-admin.py startproject janitortest python janitortest/manage.py runserver

Everything works so far...

cd janitortest/

Add postgres database support to settings.py

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

'NAME': 'django-test', # Or path to database file if using sqlite3.

'USER': 'django-test', # Not used with sqlite3.

'PASSWORD': 'password-n1234', # Not used with sqlite3.

'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.

'PORT': '5432', # Set to empty string for default. Not used with sqlite3.

}

}

python manage.py syncdb }}}

OUTPUT:

{{{ Creating tables ... Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_user_permissions Creating table auth_user_groups Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'inactivist'): test E-mail address: test@example.com Password: Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... No fixtures found. }}}

Install Janitor:

{{{

Install django-janitor

pip install django-janitor

Add janitor to INSTALLED_APPS:

INSTALLED_APPS = (

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.messages',

'django.contrib.staticfiles',

# Uncomment the next line to enable the admin:

# 'django.contrib.admin',

# Uncomment the next line to enable admin documentation:

# 'django.contrib.admindocs',

'janitor',

)

Sync the DB

python manage.py syncdb }}} OUTPUT: =======

{{{ Traceback (most recent call last): File "manage.py", line 14, in <module> execute_manager(settings) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/init.py", line 438, in execute_manager utility.execute() File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/init.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(args, options.dict) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, options) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle return self.handle_noargs(*options) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 59, in handle_noargs tables = connection.introspection.table_names() File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/db/backends/init.py", line 792, in table_names return self.get_table_list(cursor) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/db/backends/postgresql/introspection.py", line 31, in get_table_list AND pg_catalog.pg_table_is_visible(c.oid)""") File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute return self.cursor.execute(sql, params) File "/home/inactivist/sites/janitor-test/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute return self.cursor.execute(query, args) django.db.utils.DatabaseError: current transaction is aborted, commands ignored until end of transaction block }}}

The following related entries appear in the postgres log file: {{{

2012-03-29 10:34:22 PDT ERROR: relation "janitor_fieldsanitizer" does not exist at character 237 2012-03-29 10:34:22 PDT STATEMENT: SELECT "django_content_type"."id", "django_content_type"."name", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."id" IN (SELECT DISTINCT U0."content_type_id" FROM "janitor_fieldsanitizer" U0) ORDER BY "django_content_type"."name" ASC 2012-03-29 10:34:22 PDT ERROR: current transaction is aborted, commands ignored until end of transaction block 2012-03-29 10:34:22 PDT STATEMENT:
SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r', 'v', '') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid) }}}

Comments (5)

  1. Brad Montgomery repo owner

    Ok, I think I've got this fixed. You can see the pertinent changes in 4e4101fb81ac. You should be able to run "syncdb", and then set up your FieldSanitizers.

    Unfortunately, the tests are not passing, so I'm going to try to get those fixed before I put out another release.

    For now, you can install with:

    pip intall hg+https://bitbucket.org/bkmontgomery/django-janitor/
    

    or you can add the following to your requirements file:

    -e hg+https://bitbucket.org/bkmontgomery/django-janitor/#egg=django-janitor
    

    Thanks again for reporting this. I'm closing this issue, but if you run across anything else, please feel free to report it.

  2. Log in to comment