2

I have some very basic code in our contact form:

if request.method == 'POST':
    form = ContactForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data

        # send the email to the MANAGERS
        send_mail(
            'CourtListener message from "%s": %s' % (cd['name'], cd['subject']),
            cd['message'],
            cd.get('email', 'noreply@example.com'),
            manager_email_addresses, )
        # we must redirect after success to avoid problems with people using the refresh button.
        return HttpResponseRedirect('/contact/thanks/')

Complete code here

A second ago, two users sent us messages around the same time and somehow their data got transposed. In an email we got the message from one user, but the subject line from the other. Looking at the code, I can't imagine how that could have happened, unless it was upstream from Django, but in my experience, bugs are never upstream, so I'm skeptical of this theory.

Anybody have any theories on this?

Our stack is:

  • Apache in worker mode with config file here.
  • WSGI file is here
  • Behind that is fairly standard CPython
mlissner
  • 17,359
  • 18
  • 106
  • 169
  • The problem is in the definition of the contact() function, which is subject to the mutable default argument gotcha, so marking this as a duplicate. – Daniel Roseman Jul 16 '14 at 07:44
  • Ah, indeed. So basically, I should just really avoid using dicts and lists as default args to functions, unless I'm deliberately taking advantage of this. – mlissner Jul 16 '14 at 15:29
  • 1
    Yes. For me that's always a red flag in any Python code. – Daniel Roseman Jul 16 '14 at 15:33

0 Answers0