Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#12776 closed (fixed)

get_profile() may throw AttributeError instead of SiteProfileNotAvailable

Reported by: master Owned by: nobody
Component: contrib.auth Version: 1.1
Severity: Keywords: profile
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I didn't find a case to fire:
except (ImportError, ImproperlyConfigured)

But some others cases :


  • you don't provide a '.': 'accountsUserProfile'

==> ValueError

  • you mispell or forget the app_label part or the model_name part: 'accounts.', 'accXXXounts.UserProfile'

No exception is raised and the variable 'model' is returned as None.
==> AttributeError on following line: 'NoneType' object has no attribute '_default_manager'

I needed something similar for my own code, that I wrote as:

    model = ...
    if not model:
        raise SiteProfileNotAvailable
except ValueError:
        raise SiteProfileNotAvailable

Attachments (1)

12776.patch (3.8 KB) - added by brutasse 6 years ago.
Throws more SiteProfileNotAvailable, adds some verbosity

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by brutasse

Throws more SiteProfileNotAvailable, adds some verbosity

comment:2 Changed 6 years ago by brutasse

Added a patch with tests. The patch adds some more human-friendly errors as well, to be reviewed by a native English speaker.

comment:3 Changed 6 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 6 years ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r12506.

comment:5 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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