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

Fixed issue #314 - include information about view/serializer in warnings #327

Merged

Conversation

spookylukey
Copy link
Contributor

This is a replacement for #322, with changes as suggested in the review there, squashed to reduce noise in the history.

I ran this against my clients project. With #322, I was getting:

Schema generation summary:
Warnings: 616 (438 unique)
Errors:   140 (33 unique)

With this I'm getting:

Schema generation summary:
Warnings: 616 (445 unique)
Errors:   140 (33 unique)

There are a few more unique because there are a few more places where are we are adding the MyViewSet: prefix. The bigger change is that most of my messages now have MyViewSet: MySerializer instead of just MySerializer: prefix.

@codecov
Copy link

codecov bot commented Mar 8, 2021

Codecov Report

Merging #327 (52b1c88) into master (02fcef2) will decrease coverage by 0.13%.
The diff coverage is 89.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
- Coverage   98.22%   98.08%   -0.14%     
==========================================
  Files          53       54       +1     
  Lines        4729     4919     +190     
==========================================
+ Hits         4645     4825     +180     
- Misses         84       94      +10     
Impacted Files Coverage Δ
drf_spectacular/hooks.py 100.00% <ø> (ø)
tests/__init__.py 97.91% <ø> (ø)
drf_spectacular/generators.py 94.48% <60.00%> (-2.18%) ⬇️
drf_spectacular/plumbing.py 96.81% <75.00%> (+0.08%) ⬆️
drf_spectacular/openapi.py 95.31% <89.28%> (-0.53%) ⬇️
drf_spectacular/drainage.py 98.21% <100.00%> (+0.34%) ⬆️
tests/test_command.py 100.00% <100.00%> (ø)
tests/test_warnings.py 100.00% <100.00%> (ø)
drf_spectacular/contrib/django_filters.py 87.23% <0.00%> (-2.18%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02fcef2...52b1c88. Read the comment docs.

…in warnings.

The main technique for doing this in deeply nested places from which we call
`error()` or `warn()`, is to a stack of traces that get added as prefices to the
message (rather than having to pass this context information through many layers
of code).

This also fixes a set of consistency issues with warning/error messages:

- Always start message with `{serializer/view name}: ` if possible.
  This meant removing this info from the body of the message
  where we are now adding it as a prefix.
- First sentence shouldn't have a capital letter
  (the message is printed after colon from the prefix)
- Subsequent sentences should have a capital letter.
@spookylukey spookylukey force-pushed the better_traceability_in_warnings_alt1 branch from 37f8b0b to 52b1c88 Compare March 8, 2021 09:43
@tfranzel tfranzel merged commit a83ecc4 into tfranzel:master Mar 9, 2021
@tfranzel
Copy link
Owner

tfranzel commented Mar 9, 2021

i think the difference is very manageable.

The bigger change is that most of my messages now have MyViewSet: MySerializer instead of just MySerializer: prefix.

which imho is a lot better. always having a full trace including the view is more consistent and may also help when the same serializer name is used in different apps. i could already see the next person asking for this 😄

thanks again! i hope you get that number down to zero fast.

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

Successfully merging this pull request may close these issues.

2 participants