Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting the encoding on QuotedString #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Grollicus
Copy link

Allow setting the encoding of a QuotedString when it has no connection.

I tried to build the same functionality as psycopg2 (here) but maybe I've missed something as I'm not that firm on reading native python modules.

Setting encoding is used in django (here) and broke my migrations there.

Adding the resulting exception for completeness' sake and for google-ability:

% ./manage.py test
yes
Creating test database for alias 'default'...
Got an error creating the test database: database "..." already exists

Type 'yes' if you would like to try deleting the test database '...', or 'no' to cancel: Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    main()
  File "./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File ".../site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File ".../site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ".../site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File ".../site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File ".../site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File ".../site-packages/django/core/management/commands/test.py", line 55, in handle
    failures = test_runner.run_tests(test_labels)
  File ".../site-packages/django/test/runner.py", line 725, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File ".../site-packages/django/test/runner.py", line 645, in setup_databases
    debug_sql=self.debug_sql, parallel=self.parallel, **kwargs
  File ".../site-packages/django/test/utils.py", line 183, in setup_databases
    serialize=connection.settings_dict['TEST'].get('SERIALIZE', True),
  File ".../site-packages/django/db/backends/base/creation.py", line 79, in create_test_db
    run_syncdb=True,
  File ".../site-packages/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File ".../site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File ".../site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File ".../site-packages/django/core/management/commands/migrate.py", line 246, in handle
    fake_initial=fake_initial,
  File ".../site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File ".../site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File ".../site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File ".../site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File ".../site-packages/django/db/migrations/operations/models.py", line 858, in database_forwards
    schema_editor.add_constraint(model, self.constraint)
  File ".../site-packages/django/db/backends/base/schema.py", line 393, in add_constraint
    sql = constraint.create_sql(model, self)
  File ".../site-packages/django/db/models/constraints.py", line 54, in create_sql
    check = self._get_check_sql(model, schema_editor)
  File ".../site-packages/django/db/models/constraints.py", line 47, in _get_check_sql
    return sql % tuple(schema_editor.quote_value(p) for p in params)
  File ".../site-packages/django/db/models/constraints.py", line 47, in <genexpr>
    return sql % tuple(schema_editor.quote_value(p) for p in params)
  File ".../site-packages/django/db/backends/postgresql/schema.py", line 44, in quote_value
    adapted.encoding = 'utf8'
AttributeError: can't set attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant