Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3954 closed (fixed)

[patch] Fixtures for postgresql and problems with colors.

Reported by: anonymous Owned by: jacob
Component: Core (Serialization) Version: master
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: UI/UX:

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 8 years ago.
no-colors-for-sql.diff (1.8 KB) - added by anonymous 8 years ago.
no_colors_for_sql_pg1.diff (1.8 KB) - added by eduardo.padoan@… 8 years ago.
loaddata_nocolors.diff (395 bytes) - added by Vinay Sajip <vinay_sajip@…> 8 years ago.
Fix for missing disable_termcolors() in load_data

Download all attachments as: .zip

Change History (13)

Changed 8 years ago by anonymous

Changed 8 years ago by anonymous

comment:1 Changed 8 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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)

Changed 8 years ago by eduardo.padoan@…

comment:2 Changed 8 years ago by anonymous

  • 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.

Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

Fix for missing disable_termcolors() in load_data

comment:3 Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

  • 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 Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

  • Has patch set

comment:5 Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

  • Summary changed from Fixtures for postgresql and problems with colors. to [patch] Fixtures for postgresql and problems with colors.

comment:6 Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

  • Triage Stage changed from Unreviewed to Accepted

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 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:8 follow-up: Changed 8 years ago by Vinay Sajip <vinay_sajip@…>

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

comment:9 in reply to: ↑ 8 Changed 8 years ago by russellm

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