Django

Code

Ticket #4380 (new)

Opened 1 year ago

Last modified 2 months ago

Rename DEFAULT_CHARSET to OUTPUT_CHARSET (or similar)

Reported by: Simon Willison Assigned to: ctrochalakis
Component: Core framework Version: SVN
Keywords: Cc: floguy@gmail.com
Triage Stage: Accepted Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

Just spotted this in the new unicode documentation (from the unicode branch):

Do not be fooled into thinking that if you DEFAULT_CHARSET setting is set to something other than utf-8 you can use that encoding in your bytestrings! The DEFAULT_CHARSET only applies to the strings generated as the result of template rendering (and email). Django will always assume UTF-8 encoding for internal bytestrings. The reason for this is that the DEFAULT_CHARSET setting is not actually under your control (if you are the application developer). It is under the control of the person installing and using your application and if they choose a different setting, your code must still continue to work. Ergo, it cannot rely on that setting.

http://code.djangoproject.com/browser/django/branches/unicode/docs/unicode.txt?rev=5330#L57

How about renaming that setting to something more clear, like OUTPUT_CHARSET or DEFAULT_OUTPUT_CHARSET?

Attachments

default_charset_deprecation.1.diff (12.8 kB) - added by floguy on 03/18/08 12:31:15.
Replaced all DEFAULT_CHARSET references with OUTPUT_CHARSET, and added PendingDeprecationWarnings? for referencing DEFAULT_CHARSET.
0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.patch (13.7 kB) - added by ctrochalakis on 03/18/08 13:46:50.
replace-DEFAULT_CHARSET
0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.2.patch (14.0 kB) - added by ctrochalakis on 03/18/08 14:06:41.
replace-DEFAULT_CHARSET+deprecation warning
output_charset.patch (13.7 kB) - added by ctrochalakis on 03/19/08 05:27:52.

Change History

05/24/07 15:57:15 changed by Marc Fargas <telenieko@telenieko.com>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

+1 at least the setting will be a bit clearer on its purpose ;) Maybe FILE_CHARSET could be moved to TEMPLATE_CHARSET as it only affects templates ;))

but you'd rather bring that to django-devs ;)

05/24/07 18:38:45 changed by mtredinnick

Well, that'll teach me to document things.

Might be worth changing for all the good reasons you mention. I thought about it, particularly when writing that passage, because it brings the unfortunate name into relief. On a theoretical level, I'm completely in agreement. But I hate making backwards incompatible changes. If we can fake a backwards compatible hack (e.g. populate OUTPUT_CHARSET from DEFAULT_CHARSET if the former doesn't exist in the settings module), I'd be happier. That's probably achievable, without thinking too hard about it.

I'm probably in favour, but I need some time to get used to it. :-)

Best plan of all: convince Adrian and/or Jacob so that I can avoid making a decision.

Marc: FILE_CHARSET was already discussed ad infinitum on django-dev. It's not going to change because it's not just used for template input (and that fact is even documented - look at the documentation for FILE_CHARSET in settings.txt).

11/30/07 15:09:01 changed by jacob

  • stage changed from Design decision needed to Accepted.

A bit of a wart, but I think I'm vaguely +0 on deprecating DEFAULT_CHARSET and switching to OUTPUT_CHARSET since Malcolm assures me that could be done in a backwards-compatible way.

11/30/07 15:09:08 changed by jacob

  • version changed from other branch to SVN.

03/18/08 12:27:30 changed by floguy

  • cc set to floguy@gmail.com.
  • needs_docs set to 1.
  • has_patch set to 1.
  • status changed from new to assigned.
  • owner changed from nobody to floguy.

03/18/08 12:31:15 changed by floguy

  • attachment default_charset_deprecation.1.diff added.

Replaced all DEFAULT_CHARSET references with OUTPUT_CHARSET, and added PendingDeprecationWarnings? for referencing DEFAULT_CHARSET.

03/18/08 13:46:50 changed by ctrochalakis

  • attachment 0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.patch added.

replace-DEFAULT_CHARSET

03/18/08 13:50:42 changed by floguy

  • owner changed from floguy to ctrochalakis.
  • status changed from assigned to new.

That second patch is cleaner than my first one.

03/18/08 14:06:41 changed by ctrochalakis

  • attachment 0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.2.patch added.

replace-DEFAULT_CHARSET+deprecation warning

03/18/08 14:08:55 changed by ctrochalakis

Added a deprecation warning as Eric did in the first patch. The warning is triggered if the DEFAULT_CHARSET is set.

03/18/08 20:19:53 changed by mtredinnick

At a minimum there needs be a "New in Django develpoment version" marker in the settings documentation. I'd also leave a docs entry in place for DEFAULT_CHARSET and refer it to OUTPUT_CHARSET with a note that this was the older way of doing it. That way people reading the docs and searching for the setting they have in their code will still find an entry.

03/18/08 20:20:13 changed by mtredinnick

  • needs_better_patch set to 1.
  • needs_docs deleted.

03/19/08 05:27:52 changed by ctrochalakis

  • attachment output_charset.patch added.

03/19/08 05:59:32 changed by ctrochalakis

  • needs_better_patch deleted.

Added a "new in development version" marker. Also, DEFAULT_CHARSET section in retained in the settings.txt file, and refers to OUTPUT_CHARSET.


Add/Change #4380 (Rename DEFAULT_CHARSET to OUTPUT_CHARSET (or similar))




Change Properties
Action