-
Notifications
You must be signed in to change notification settings - Fork 9
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
DISCO-3033 refactor city based suggest #667
base: main
Are you sure you want to change the base?
Conversation
e5810d3
to
c9bc733
Compare
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.
Looks good, thanks! r+wc.
def prioritize_custom_location(self) -> "Location": | ||
"""Update city, region, and country with custom fields if all custom fields exist.""" | ||
if all([self.city_custom, self.regions_custom, self.country_custom]): | ||
self.city = self.city_custom |
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.
Overwriting could be problematic as we will lose the original geolocation which is used by other consumers such as the logging middleware. I think we can either return a tuple of (country, regions, city) or just return a new Location
with country, regions, and city are set to the custom counterparts.
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.
this should be fine as we're invoking this method on a copy of the geolocation and not the original object.
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.
another way we could try is moving this helper function out of the model class and into backend.py
and having it return a new location with the overwrite so as not to mess with the middleware. what do you think @ncloudioj ?
|
||
validate_suggest_custom_location_params(city, region, country) | ||
|
||
geolocation = request.scope[ScopeKey.GEOLOCATION].model_copy( |
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.
As of now, requests w/ the custom location is much fewer than those w/o it. So let's update it conditionally.
if country and region and city:
geolocation = request.scope[ScopeKey.GEOLOCATION].model_copy(...)
else:
geolocation = request.scope[ScopeKey.GEOLOCATION]
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.
hmm since we're overwriting city, region & country down the line, I feel more comfortable working with the copy in this case. also we do some validation right before this so it either errors out before getting here if we have missing fields or the values are all None
which is the default.
References
JIRA: DISCO-3033
Description
Location
model to return preferred location based on custom values. Also added some more validation to query params.PR Review Checklist
Put an
x
in the boxes that apply[DISCO-####]
, and has the same title (if applicable)[load test: (abort|warn)]
keywords are applied (if applicable)