Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#3954 closed (fixed)

[patch] Fixtures for postgresql and problems with colors.

Reported by: anonymous Owned by: Jacob
Component: Core (Serialization) Version: dev
Severity: Keywords: fixtures, loaddata, sequences, postgresql
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have this fixture (yaml format):

- model: sites.Site
  pk: 1
  fields:
    domain: localhost:8000
    name: localhost:8000

I try to load this fixture:

> ./manage.py loaddata sites
Loading 'sites' fixtures...
Installing yaml fixture 'sites' from ...
Installed 1 object(s) from 1 fixture(s)
Traceback (most recent call last):
  File "./manage.py", line 12, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.5/site-packages/django/core/management.py", line 1668, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "/usr/local/lib/python2.5/site-packages/django/core/management.py", line 1582, in execute_from_command_line
    action_mapping[action](args[1:], int(options.verbosity))
  File "/usr/local/lib/python2.5/site-packages/django/core/management.py", line 1412, in load_data
    cursor.execute(line)
  File "/usr/local/lib/python2.5/site-packages/django/db/backends/util.py", line 12, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near " "
LINE 1: SELECT setval('django_site_id_seq', ( [3...
        ^

If I use patch show-sql.diff (SELECT is with colors):

> ./manage.py loaddata sites
Loading 'sites' fixtures...
Installing yaml fixture 'sites' from ...
Installed 1 object(s) from 1 fixture(s)
SELECT setval('django_site_id_seq', (SELECT max("id") FROM "django_site"));
'\x1b[33mSELECT\x1b[0m setval(\'\x1b[32;1mdjango_site_id_seq\x1b[0m\', (\x1b[33mSELECT\x1b[0m max(\x1b[32;1m"id"\x1b[0m) \x1b[33mFROM\x1b[0m \x1b[1m"django_site"\x1b[0m));'
Traceback (most recent call last):
  ...

If I use patch no-colors-for-sql.diff, loading is ok.

I use postgresql 8.2.3, psycopg 2.0.5 and python 2.5.1 rc1 (Ubuntu 6.04 Feisty Fawn), but I also tried psycopg 1.1.21 and/or python 2.4.4 (four unsuccessful attempts and two successful attempts - patch is only for psycopg2).

Attachments (4)

show-sql.diff (480 bytes ) - added by anonymous 17 years ago.
no-colors-for-sql.diff (1.8 KB ) - added by anonymous 17 years ago.
no_colors_for_sql_pg1.diff (1.8 KB ) - added by eduardo.padoan@… 17 years ago.
loaddata_nocolors.diff (395 bytes ) - added by Vinay Sajip <vinay_sajip@…> 17 years ago.
Fix for missing disable_termcolors() in load_data

Download all attachments as: .zip

Change History (13)

by anonymous, 17 years ago

Attachment: show-sql.diff added

by anonymous, 17 years ago

Attachment: no-colors-for-sql.diff added

comment:1 by anonymous, 17 years ago

Maybe this part of django can be relevant (django.core.management.py, 49-51):

# Disable terminal coloring on Windows, Pocket PC, or if somebody's piping the output.
if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty():
    disable_termcolors()

Attempt with pipe (and without patches):

./manage.py loaddata sites | cat -
Loading 'sites' fixtures...
Installing yaml fixture 'sites' from ...
Installed 1 object(s) from 1 fixture(s)

by eduardo.padoan@…, 17 years ago

Attachment: no_colors_for_sql_pg1.diff added

comment:2 by anonymous, 17 years ago

Patch needs improvement: set

Marked #4012 as a duplication of this.
no_colors_for_sql_pg1.diff is a patch for the psycopg 1.x layer.

by Vinay Sajip <vinay_sajip@…>, 17 years ago

Attachment: loaddata_nocolors.diff added

Fix for missing disable_termcolors() in load_data

comment:3 by Vinay Sajip <vinay_sajip@…>, 17 years ago

Patch needs improvement: unset

The problem appears to be caused by a missing call to disable_termcolors() in load_data(). Fixed in patch: loaddata_nocolors.diff.

comment:4 by Vinay Sajip <vinay_sajip@…>, 17 years ago

Has patch: set

comment:5 by Vinay Sajip <vinay_sajip@…>, 17 years ago

Summary: Fixtures for postgresql and problems with colors.[patch] Fixtures for postgresql and problems with colors.

comment:6 by Vinay Sajip <vinay_sajip@…>, 17 years ago

Triage Stage: UnreviewedAccepted

Hope it's OK to set this as Accepted, since it seems to be a clear-cut bug (raised by another user). Don't feel it needs any documentation or unit test.

comment:7 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [5102]) Fixed #3954 -- Disabled termcolors when loading fixtures. Well spotted, Vijay Sajip.

comment:8 by Vinay Sajip <vinay_sajip@…>, 17 years ago

Errr... that's "Vinay", not "Vijay". Thanks for committing the fix!

in reply to:  8 comment:9 by Russell Keith-Magee, 17 years ago

Replying to Vinay Sajip <vinay_sajip@yahoo.co.uk>:

Errr... that's "Vinay", not "Vijay". Thanks for committing the fix!

Humble apologies. For what it's worth, I got your name right in the AUTHORS file :-)

Note: See TracTickets for help on using tickets.
Back to Top