Don't trim attribute values when field.max_length is None #67
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.
Issue
When mapping SAML2 attribute values to a Django user object, the backend compares the SAML2 value's length with the user object field's
max_lengthto determine if trimming is required.Some Django field types do not set a numeric
max_lengthattribute, such asIntegerFieldandPositiveIntegerField. Themax_lengthattribute of these classes isNone(inherited from their parent class,Field).In the trace below,
max_lengthisNone(the field is aPositiveIntegerField) so we getTypeError: unorderable types: int() > NoneType()when comparinglen(value) > field.max_lengthSolution
Check that
field.max_length is not Nonebefore comparinglen(value) > field.max_lengthLinks to Django 1.11.3 Field source for reference:
django/db/models/fields/init.py#L146 (setting
self.max_length=Noneby default)django/db/models/fields/init.py#L1804 (
IntegerFielddoes not override self.max_length)Environment
djangosaml 0.16.1
Django 1.11.3
Python 3.5.2
Ubuntu 16.04.2 LTS
Full trace