Serialize avatar URL in user resource only when URLs available

Review Request #9457 — Created Dec. 19, 2017 and submitted

brennie
Review Board
release-3.0.x
4616
ed1a82f...
reviewboard

Previously we assumed that all avatar services would return URLs.
However, it is possible that the service has yet to be configured for a
user (e.g., they haven't uploaded an avatar yet for the
FileUploadAvatarService) or the avatar service returns bad data. In
these cases, we now wrap the serialization in a try..except to ensure
that we don't cause exceptions that crash the resource.

Additionally, we also ensure that we serialize the avatar_urls field
as {} instead of None when there are no URLs to simplify
deserialization logic.

Ran unit tests.

  • 0
  • 0
  • 5
  • 0
  • 5
Description From Last Updated
david
  1. 
      
  2. reviewboard/webapi/resources/user.py (Diff revision 1)
     
     
     
     
     
     
     
     

    This whole thing could be just return urls and urls.get('1x')

  3. reviewboard/webapi/tests/test_user.py (Diff revision 1)
     
     

    Single quotes.

  4. 
      
brennie
david
  1. Ship It!

  2. 
      
brennie
chipx86
  1. 
      
  2. reviewboard/webapi/resources/user.py (Diff revision 3)
     
     
     
     
     
     
     
     
     

    Maybe worth having this return {} when there are no URLs? Simplifies the above code, simplifies clients who no longer need to check for null but can instead just check for the presence of certain avatars (or check falsiness).

  3. reviewboard/webapi/tests/test_user.py (Diff revision 3)
     
     

    Plurals are wrong here. "avatar service"?

  4. 
      
brennie
chipx86
  1. 
      
  2. Can you update the description to also mention the change to the avatar_urls field? That'll make it easier to remember while writing release notes, and when coming across the modification down the road.

  3. 
      
brennie
david
  1. Ship It!
  2. 
      
brennie
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.0.x (f50e598)
Loading...