Skip to content

Allow modifying pep images with same name #1556

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

Closed
wants to merge 2 commits into from

Conversation

lukpueh
Copy link

@lukpueh lukpueh commented Feb 12, 2020

Fixes #824

Currently, peps.converters.add_pep_image does not allow to add an image that already exists in the database for the same name. As a consequence images cannot be updated.

This PR modifies peps.converters.add_pep_image to also update the image db record if the corresponding file has changed as per filecmp.cmp' This requires removing the file prior to the db update, because the django FileField does not override existing files.

Alternatives to the ad hoc removal of the file in add_pep_image include passing a custom OverwriteStorage to the used ImageField, see e.g.:

https://code.djangoproject.com/ticket/4339
https://stackoverflow.com/questions/9522759/imagefield-overwrite-image-file-with-same-name

Currently, 'peps.converters.add_pep_image' does not allow to add an
image that already exists in the database for the same name. As a
consequence images cannot be updated.

This commit modifies 'peps.converters.add_pep_image' to also update
the image db record if the corresponding file has changed as per
'filecmp.cmp'. This requires removing the file prior to the db
update, because the django 'FileField' does not override existing
files.

Alternatives to the ad hoc removal of the file in 'add_pep_image'
include passing a custom 'OverwriteStorage' to the used
'ImageField', see e.g.:

https://code.djangoproject.com/ticket/4339
https://stackoverflow.com/questions/9522759/imagefield-overwrite-image-file-with-same-name

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@lukpueh
Copy link
Author

lukpueh commented Feb 13, 2020

I just skimmed through the peps git history to see how other image updates were propagated in the past. It generally doesn't seem to have happened often.

One case that I found is pep-0602-example-release-calendar.png. Interestingly, the html img tag on the pep site does point to the latest version of the image, i.e. pep-0602-example-release-calendar_cTnYawu.png. @ambv, @brettcannon, do you know how this is possible? Did I miss something in the peps conversion script? Or did you patch the html or db manually on the production server? Thanks!

@brettcannon
Copy link
Member

@lukpueh I'm not aware of any special thing done for that PEP.

@ncoghlan
Copy link

ncoghlan commented Mar 1, 2020

There was at least one point where we accidentally broke PEP image publication in general, so I was wondering if it could be that the earlier versions of the image didn't make it into the website DB.

However, I don't think the image commit history backs that up.

Test a recent change in `add_pep_image` that allows modifying
images.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@lukpueh lukpueh force-pushed the allow-modify-pep-image branch from 3c870e9 to bc91a39 Compare March 4, 2020 16:58
Copy link
Author

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a test for my patch. While writing it I found another little issue (see comment inline), which suggests to use my alternative solution (override on upload). What are others' thoughts?

It would be nice to fix this. Pep 458 still references an outdated file, although the repo has the correct one.

Thanks


# We need to remove a prior uploaded file to fix an inconsistency
# between db and filesystem.
# TODO: This should be dealt with in page.model or converters module
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's some additional info for this line;

A prior test that calls add_pep_image might have already created the 'pep-3001-1.png' file, without persisting the db object. Now a new call to add_pep_image will check for objects, whose name ends with 'pep-3001-1.png', and, since it does not find any, create it anew along with the file. But since Django does not allow to override files it duplicates it using a random infix, e.g 'pep-3001-1_0u7tlLY.png', which is also used as a name on the object.

Now due to the endswith-check and with the random infix, each subsequent attempt to add 'pep-3001-1.png' with add_pep_image, will also duplicate it the object and file.

Maybe we should just override images on upload as suggested as alternative fix in the PR description?

@hugovk
Copy link
Member

hugovk commented Dec 1, 2022

This can be closed: after implementing PEP 676, PEP pages are now deployed directly from https://github.com/python/peps to https://peps.python.org/.

It does however highlight there's some old PEP-handling code in the repo which is no longer needed and can be removed.

@hugovk
Copy link
Member

hugovk commented Aug 12, 2024

@lukpueh I don't have permission to close things in this repo. Please could you close this PR?

@lukpueh lukpueh closed this Aug 12, 2024
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.

Edits to an image don't show up on the PEP page
4 participants