Skip to content
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

Reveal previously hidden AttributeErrors and TypeErrors #3668

Merged
merged 1 commit into from
Nov 27, 2015

Conversation

akx
Copy link
Contributor

@akx akx commented Nov 24, 2015

This ensures AttributeErrors and TypeErrors do not get hidden when DRF is just looking for a get_queryset().

@tomchristie
Copy link
Member

Prob worth issuing as two separate PRs.
The get_queryset ones are simple enough and would prob accept those as-is.
The .count() I'd want to give more review to.

@akx
Copy link
Contributor Author

akx commented Nov 25, 2015

Sure, I'll snip that one out.

@@ -169,7 +170,7 @@ class Meta:
file_path_field = FilePathField(path='/tmp/')
""")

self.assertEqual(unicode_repr(TestSerializer()), expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressing any windows test failures should probably be treated as a separate PR.
I assume that's what this change is about, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- though it's a bit odd that repr would act differently across platforms...

@akx
Copy link
Contributor Author

akx commented Nov 26, 2015

I'll split the test stuff into yet another PR. :)

@akx akx force-pushed the exc-hiding branch 2 times, most recently from 93e344f to 447ad2a Compare November 26, 2015 13:25

class GetQuerysetRaises(generics.ListAPIView):
def get_queryset(self):
raise CheckAttributeError("Something terrible occurred deep down in the call stack")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a regular AttributeError would be okay here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps return self.this_attribute_does_not_exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I subclassed AttributeError for the test for the purpose of being able to check for that exact exception being propagated up, which was the point of the patch in the first place :)

@tomchristie
Copy link
Member

Okay, on review at this point I'd actually rather have this, but without the test cases.
It's a case of evidently improved behavior, and I think they'd actually add more noise than value in this case. Otherwise fix looks good, so happy to move once tests have been dropped. 👍

@akx
Copy link
Contributor Author

akx commented Nov 27, 2015

Well, if you're sure! I'll take the test cases out.

Quietly catching `AttributeError` and `TypeError` when calling
`get_queryset()` is rather insidious, as those exceptions get caught no
matter where they might happen in the call stack.
@akx
Copy link
Contributor Author

akx commented Nov 27, 2015

Tests are now gone, @tomchristie.

@tomchristie tomchristie added this to the 3.3.2 Release milestone Nov 27, 2015
@tomchristie
Copy link
Member

May seem counter-intuitive, but they come with an associated cost, and can be okay not to strictly test against obviously better/cleaner behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants