-
Notifications
You must be signed in to change notification settings - Fork 535
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
Fixes #7679: Change anonymous user image url/picture_type to a null value #7715
Conversation
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.
the migrations in migrations
are manually created, alas. You will need a snippet of sql that would change the column default. I would read the other migrations for inspiration but shout up if you can't figure it out.
src/olympia/users/models.py
Outdated
@@ -274,7 +275,7 @@ def picture_path_original(self): | |||
def picture_url(self): | |||
from olympia.amo.templatetags.jinja_helpers import user_media_url | |||
if not self.picture_type: | |||
return settings.STATIC_URL + '/img/zamboni/anon_user.png' |
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.
you can't change this in the Addon
model because it's still used in legacy frontend views. You'll need to handle in BaseUserSerializer
instead
@eviljeff I've made the changes, please have a look now. On the issue @diox said that we use Here is the sql that it generated:
Not sure if these were missed earlier or what's the case here. Please let me know :) |
src/olympia/accounts/serializers.py
Outdated
@@ -45,7 +45,10 @@ def get_permissions(self, obj): | |||
|
|||
# Used in subclasses. | |||
def get_picture_url(self, obj): | |||
return absolutify(obj.picture_url) | |||
if obj.picture_url and \ |
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.
I know it's valid python, but we don't use \
to split lines in addon-server code. Please rewrite with ( ... )
instead.
src/olympia/accounts/serializers.py
Outdated
@@ -45,7 +45,10 @@ def get_permissions(self, obj): | |||
|
|||
# Used in subclasses. | |||
def get_picture_url(self, obj): | |||
return absolutify(obj.picture_url) | |||
if obj.picture_url and \ | |||
not obj.picture_url.endswith('/img/zamboni/anon_user.png'): |
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.
Rather than testing obj.picture_url
here, test obj.picture_type
- because we know it'll be None
now.
@@ -0,0 +1,2 @@ | |||
ALTER TABLE `users` | |||
MODIFY `picture_type` varchar(75) NULL DEFAULT NULL; |
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 looks good to me - did you test locally with make update_db
?
No idea about the auto generated SQL - you can ignore it.
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.
I ran this using schematic src/olympia/migrations/
after I was using make shell
to enable a tty on the container.
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.
Also, I don't see if there is make udpate_db
command. There is update_docker
though
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.
make update_db
is an inner make command, inside the docker container - you can run it with docker-compose exec web make update_db
- though it just does schematic src/olympia/migrations/
anyway so you did the same thing.
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.
Oh, awesome! I'll keep a note of that for the subsequent PRs. Thanks :)
@eviljeff Done with the changes, can you please take another pass here? |
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 great - although it's not many lines of code anything involving database migrations and model changes is more complicated. r+
Thanks for the |
We'll have to see when it deploys to the servers (-dev within the hour; stage on Tuesday, production on Thursday) if there any weird differences in the database schemas that stop the migration from running - it happens often 🤞 |
Oh! But why would that happen? Even if django migrations are not used, and raw SQL is ran, the SQL code would be same on dev/stage/production; isn't it? |
When most of the tables were created there weren't many standards about what django models should create in the database (and some data even pre-dates AMO's rewrite using django 9 years ago). When you create a database locally you get the schema django wants now, which is in some cases subtlety different. |
Fixes mozilla/addons#5303
Requesting user from API: (https://addons-server.readthedocs.io/en/latest/topics/api/accounts.html#get--api-v3-accounts-account-(int-user_id|string-username)-) will now return
null
inpicture_type
andpicture_url
if the profile picture is not set.The only last bit that should be included in this patch is the migration (since models are changed). I'm having this build running with docker-compose and when I try to do
make shell
and then run db migrations viapython manage.py makemigrations
, it tells me that no changes detected.Further to this, I explored the codebase and found that there is just one migration folder referring to all the SQL files. I'm curious to know how do we generate these files/migrations for that say.
PRs open for the same issue.
Fixes #ISSUENUM
at the top of your PR.