[WIP] Add timezone to user in API
Review Request #7881 — Created Jan. 16, 2016 and discarded
Timezone has been added to the User resource in the API, this was a request.
The possible values of timezone are the timezone options available in the User settings page.
The User's timezone is queried along with the rest of the User's information in order to reduce the number of queries made to the database.
Accessed a list of Users (/api/users/) and a single user (/api/users/admin/) in order to confirm correct data (Local Review Board had 2 users total with different Timezones).
Performed a unit test to ensure that a minimal amount of queries are performed (when a User is queried, their profile is joined).
Unit test consisted of starting with the "unoptimized" version (which made an extra query) and fixing until the data was retrieved without the extra query being made.
Description | From | Last Updated |
---|---|---|
Col: 19 E231 missing whitespace after ':' |
reviewbot | |
Col: 26 E231 missing whitespace after ':' |
reviewbot | |
Col: 24 E203 whitespace before ':' |
reviewbot | |
local variable 'e' is assigned to but never used |
reviewbot | |
Col: 35 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 23 E203 whitespace before ':' |
reviewbot | |
Col: 29 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 35 E127 continuation line over-indented for visual indent |
reviewbot | |
Do we think folks will care about keeping their timezones private? Should we add timezone to this list? |
mike_conley | |
It's usually not a good idea to catch Exception, since that's a really generic Exception, and might get raised for … |
mike_conley | |
We're doing the subquery twice, which we can avoid by making use of a couple extra parameters to extra(): return … |
chipx86 | |
Should have a trailing comma in the last list item. |
chipx86 |
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/user.py Tool: Pyflakes Processed Files: reviewboard/webapi/resources/user.py
-
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/user.py Tool: Pyflakes Processed Files: reviewboard/webapi/resources/user.py
-
-
Do we think folks will care about keeping their timezones private? Should we add timezone to this list?
-
According to the Django 1.9 docs, we're supposed to avoid
extra
at all costs, but I guess if it's good enough for is_private, it's probably fine... -
It's usually not a good idea to catch Exception, since that's a really generic Exception, and might get raised for reasons other than the fact that the user does not exist when accessing timezone.
If we're certain we want to handle this case (I'm not sure how it could happen), maybe we should do:
if not user: logging.error(...) return user.timezone
If we don't care about this case, then I'm pretty sure we don't need this serializer.
-
Also, on your next pass, would you mind altering your Summary / Description / Testing Done to adhere to this document? Thanks!
- Groups:
- Change Summary:
-
Attempting to adhere to documentation principles.
- Summary:
-
-Added User's Timezone to API (/api/user/<user>Add timezone to user in API
- Bugs:
- Description:
-
~ -Fixed missing brackets for user.getprofile().timezone
~ Timezone has been added to the User resource in the API.
- - - - -Catch Exception if a profile doesn't exist
- - - - -Removed miscellaenous code -Need to Prefetch profiles for the Users Queryset
- - - - -Reworked Timezone implementation to reduce the number of queries made to the Database.
Timezone is now an attribute that is accessible from the User resource.
~ The possible values of Timezone are the timezone options available in the User settings page. ~ The possible values of timezone are the timezone options available in the User settings page. + + The User's timezone is queried along with the rest of the User's information in order to reduce the number of queries made to the database.
~ An example of the attribute in XML format, omitting other User resource details, would be:
~ This feature was a request
- <timezone>US/Eastern</timezone>
- Change Summary:
-
Changed the way timezone is retrieved in order to avoid exceptions and ensure proper handling in the case that a Profile does not exist.
- Diff:
-
Revision 4 (+11 -1)
-
Tool: Pyflakes Processed Files: reviewboard/webapi/resources/user.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/user.py
- Change Summary:
-
Fixing description.
- Description:
-
~ Timezone has been added to the User resource in the API.
~ Timezone has been added to the User resource in the API, this was a request.
~ Timezone is now an attribute that is accessible from the User resource.
~ The possible values of timezone are the timezone options available in the User settings page.
- The possible values of timezone are the timezone options available in the User settings page. The User's timezone is queried along with the rest of the User's information in order to reduce the number of queries made to the database.
- - This feature was a request
-
This looks good to me, but I'm only 80% confident that
getattr
is the right move. Let's wait for at least one other mentor to chime in. Thanks!
-
-
We're doing the subquery twice, which we can avoid by making use of a couple extra parameters to
extra()
:return query.extra( tables=['accounts_profile'], where=['accounts_profile.user_id=auth_user.id'], extra={ 'is_private': 'accounts_profile.is_private', 'timezone': 'accounts_profile.timezone', } )
- Change Summary:
-
Added missing trailing comma.
Removed serialized function.Need to expose timezone in the User resource!
- Diff:
-
Revision 5 (+3 -1)
-
Tool: Pyflakes Processed Files: reviewboard/webapi/resources/user.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/resources/user.py