Opened 18 years ago
Closed 18 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: | no | UI/UX: | no |
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)
by , 18 years ago
Attachment: | ticket2866.diff added |
---|
comment:1 by , 18 years ago
Component: | Admin interface → Database wrapper |
---|
comment:2 by , 18 years ago
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 by , 18 years ago
Summary: | Allowing DatabaseWrapper to support extra kwargs as settings.DATABASE_OPTIONS → [patch] Allowing DatabaseWrapper to support extra kwargs as settings.DATABASE_OPTIONS |
---|
comment:4 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Diff to add settings.DATABASE_OPTIONS and kwargs on DatabaseWrapper