Opened 12 years ago
Closed 11 years ago
#2866 closed enhancement (fixed)
[patch] Allowing DatabaseWrapper to support extra kwargs as settings.DATABASE_OPTIONS
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | UI/UX: |
Description
It would be nice to support extra keyword arguments on backends.*.DatabaseWrapper to tweak backend-specific behaviour of connect().
For example, MySQLdb supports charset keyword argument that can be used to set-default-character-set as utf8.
Allowing extra keyword arguments works as follows:
- specify {'charset': 'utf8'} on settings.DATABASE_OPTIONS (which defaults to empty dictionary)
- settings.DATABASE_OPTIONS is passed to DatabaseWrapper as keyword arguments: (
connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
) - DatabaseWrapper.init() saves kwargs as self.options
- on DatabaseWrapper.cursor(), which build connection as needed, passes self.options as extra keyword argument:
self.connection = Database.connect(**kwargs)
Attached diff includes changes on django.conf.global_settings, django.db.init, and django.db.backends.*.base.
Please note that currently kwargs are just ignored on ado_mssql (that backend does not support extra kwargs).
Attachments (1)
Change History (5)
Changed 12 years ago by
Attachment: | ticket2866.diff added |
---|
comment:1 Changed 12 years ago by
Component: | Admin interface → Database wrapper |
---|
comment:2 Changed 12 years ago by
Being able to pass an additional 'charset' argument to the MySQLdb connection is very important, as there are many occasions when the backend will raise the dreaded "Warning: Data truncated for column '...' at row ..." otherwise. Please commit this patch, or one of the others found in similar tickets.
comment:3 Changed 11 years ago by
Summary: | Allowing DatabaseWrapper to support extra kwargs as settings.DATABASE_OPTIONS → [patch] Allowing DatabaseWrapper to support extra kwargs as settings.DATABASE_OPTIONS |
---|
comment:4 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Diff to add settings.DATABASE_OPTIONS and kwargs on DatabaseWrapper