stormpath / stormpath-django

Django plugin for Stormpath
Apache License 2.0
38 stars 19 forks source link

User creation raises AttributeError when app's default account store is an Organization. #88

Open rbwinslow opened 7 years ago

rbwinslow commented 7 years ago

The get_default_is_active function is invoked at multiple points during user model instantiation, due to its use in field definitions and synchronization with Stormpath accounts. In its access of the underlying Stormpath Python SDK's application object and connected resources, this function assumes that the application's default account store is a Directory:

directory = APPLICATION.default_account_store_mapping.account_store
verif_email = directory.account_creation_policy.verification_email_status

If, however, one has mapped the default account store for one's application to an Organization instead of a Directory in one's Stormpath dashboard, the resource object assigned to the directory variable will actually be an instance of the Organization class. Unlike the Directory class, instances of Organization lack an account_creation_policy attribute, leading to the aforementioned AttributeError: "Organization has no attribute 'account_creation_policy'"

I have tried a few different approaches to user model object creation, including get_user_model().objects.create(…) and get_user_model()(is_active=True) (since the definition of the is_active field is one of the places where get_default_is_active is called). All such user model instantiation ends in the same place: AttributeError.