fix: issue with phone number lib being imported when not used #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Crash was being caused by assuming
phonenumbers
was being used, even when not enabled. This PR checks to see if the library is included, for backwards compatibility, before including it.Motivation and Context
When you view the 2FA "profile" page, it calls
backup_phones()
directly from the phone plugin, which causes afrom .models import PhoneDevice
This then means that the
PhoneDevice
model is known to django's model registry and it gets associated with thetwo_factor
rather thantwo_factor.plugins.phonenumber
.It does not cause a problem right after because the
PhoneDevice
sits on the end of the list of available models for checking to see if a user has 2FA.Later on though in device_classes, when you look at a user with no 2FA methods it crashes because it tries to look up data on that non-existent table.
In short: After the first call to
backup_phones()
, the django process then erroneously has PhoneDevice in it's model registry. After that,django_otp.device_classes
picks upPhoneDevice
as one of the available options and any timedevices_for_user
is called, we see the error.Open Issues
tbc
How Has This Been Tested?
Tested accessing profile page without phone number 2FA enabled.
Screenshots (if appropriate):
Types of changes
Checklist: