Django

Code

Ticket #3448 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

python help() parsing problem for django.core.mail

Reported by: Michael VanLandingham <m.vanland@gmail.com> Assigned to: jacob
Milestone: Component: Documentation
Version: SVN Keywords: django.core.mail, help, docs
Cc: poj+django@lysator.liu.se Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Error when accessing django.core.mail through python help()

EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined 

In python help(), if I do:

help> django.core.mail

I get:

problem in django.core.mail - EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined.

Other things in the django.core package display their docstrings and such.. It seems like something basic, but I didn't see anything obvious.

I'm on OS X 10.4.8, python 2.4.4, installed the source from the svn repository, e.g. 'python setup.py install'

Attachments

core_mail_help.diff (2.1 kB) - added by Per Jonsson <poj@lysator.liu.se> on 02/22/07 03:44:53.
core_mail_help-v2.diff (2.9 kB) - added by Per Jonsson <poj@lysator.liu.se> on 02/23/07 09:04:02.

Change History

02/06/07 22:50:27 changed by SmileyChris

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

I'd guess it's due to the following lines:

def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):
def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):

It could be fixed rather easily by setting those default arguments inside of the functions if they're None. Alternately, you could just set the environment variable or use manage.py shell.

Marked as decision needed since it's pretty trivial. If someone who cared was to write up a patch, it may convince a committer to patch rather than close ;)

02/10/07 03:12:00 changed by anonymous

  • stage changed from Design decision needed to Accepted.

The change suggested by SmileyChris? is indeed the correct fix. We should never refer to settings.* in default arguments because it removes the ability to manually configure the settings (via settings.configure()), as well as causing problems as in this bug. Use None for the default argument (which is read at import time) and inside the function do test for None and replace it with the settings.XYZ value; we require settings to have already be configured in some fashion before actually executing any functions, so this is safe.

02/10/07 03:24:59 changed by mtredinnick

(Last comment was from me.)

02/22/07 03:44:53 changed by Per Jonsson <poj@lysator.liu.se>

  • attachment core_mail_help.diff added.

02/22/07 03:47:04 changed by Per Jonsson <poj@lysator.liu.se>

  • cc set to poj+django@lysator.liu.se.
  • has_patch set to 1.

I've written a patch that implements the suggestions in this ticket.

02/23/07 08:46:49 changed by Per Jonsson <poj@lysator.liu.se>

  • stage changed from Accepted to Ready for checkin.

02/23/07 09:04:02 changed by Per Jonsson <poj@lysator.liu.se>

  • attachment core_mail_help-v2.diff added.

02/23/07 09:05:49 changed by Per Jonsson <poj@lysator.liu.se>

Realised when reading another ticket that the original patch didn't update the documentation in docs/email.txt

The new version fixes that problem.

02/25/07 23:19:32 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [4574].


Add/Change #3448 (python help() parsing problem for django.core.mail)




Change Properties
Action