-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix relational fields without to_fields
attribute.
#3635
Conversation
@@ -92,7 +92,7 @@ def _get_fields(opts): | |||
|
|||
|
|||
def _get_to_field(field): | |||
return field.to_fields[0] if field.to_fields else None | |||
return field.to_fields[0] if hasattr(field, 'to_fields') else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the new line doesn't check whether to_fields
is None
or not
Sorry for multiple commits, that should be the final one. |
Wondering whether we need a test here - most likely we do |
@@ -92,7 +92,7 @@ def _get_fields(opts): | |||
|
|||
|
|||
def _get_to_field(field): | |||
return field.to_fields[0] if field.to_fields else None | |||
return getattr(field, 'to_fields', None) and field.to_fields[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we us hasattr
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomchristie no, cf my previous outdated comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack - ignore my comment there. Incorrect.
For simple cases I'm kinda okay with us simply switching out a more brittle style for a safer style. A test case would be appreciated, but would probably accept either way. |
Agreed – I could definitely add a test case, but might take a couple days. |
Relation fields no to_fields attribute attribute break serializer
to_fields
attribute.
Fixes issue 3634