Opened 10 years ago

Closed 10 years ago

#3448 closed (fixed)

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

Reported by: Michael VanLandingham <m.vanland@…> Owned by: Jacob
Component: Documentation Version: master
Severity: Keywords: django.core.mail, help, docs
Cc: poj+django@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (2)

core_mail_help.diff (2.1 KB) - added by Per Jonsson <poj@…> 10 years ago.
core_mail_help-v2.diff (2.9 KB) - added by Per Jonsson <poj@…> 10 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 10 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

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 ;)

comment:2 Changed 10 years ago by anonymous

Triage Stage: Design decision neededAccepted

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.

comment:3 Changed 10 years ago by Malcolm Tredinnick

(Last comment was from me.)

Changed 10 years ago by Per Jonsson <poj@…>

Attachment: core_mail_help.diff added

comment:4 Changed 10 years ago by Per Jonsson <poj@…>

Cc: poj+django@… added
Has patch: set

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

comment:5 Changed 10 years ago by Per Jonsson <poj@…>

Triage Stage: AcceptedReady for checkin

Changed 10 years ago by Per Jonsson <poj@…>

Attachment: core_mail_help-v2.diff added

comment:6 Changed 10 years ago by Per Jonsson <poj@…>

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

The new version fixes that problem.

comment:7 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

Fixed in [4574].

Note: See TracTickets for help on using tickets.
Back to Top