Skip to content
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

Svg image stored as File object make folder list crash #1513

Open
fabien-michel opened this issue Jan 8, 2025 · 6 comments
Open

Svg image stored as File object make folder list crash #1513

fabien-michel opened this issue Jan 8, 2025 · 6 comments

Comments

@fabien-michel
Copy link
Contributor

I don't know how it happened, but 4 years ago an svg file was uploaded using filer and it was stored in database as a File and not an Image object. (still has `'image/svg+xml' mime though)

Since "recent" modifications of filer, this situation make filer crash when trying to list the folder with this file.

It crash here

return self.get_admin_url("expand")

because the expand admin url, does not exists in FileAdmin here:
def get_urls(self):

Because the URL exists in ImageAdmin, and in normal scenario a SVG file is stored as an Image, it doesn't fail.

@fabien-michel
Copy link
Contributor Author

fabien-michel commented Jan 8, 2025

I've found 6 files of 585 which are SVG but stored as File

@jrief
Copy link
Collaborator

jrief commented Jan 8, 2025

does this happen with all SVG files or only specific ones?

@0911R00
Copy link

0911R00 commented Jan 21, 2025

Just uploaded a svg-file with django-filer (3.1.3) in django-cms (4.1.4). On redirect after the upload to http://127.0.0.1:8000/de/admin/filer/folder/1/list/ an error appears:

Reverse for 'filer_image_expand_view' not found. 'filer_image_expand_view' is not a valid view function or pattern name.

Error during template rendering

In template (...)\venv\Lib\site-packages\filer\templates\admin\filer\folder\directory_table_list.html, error at line 142

<a href="{% if 'svg' in file.mime_type %}{% url 'admin:filer_image_expand_view' file.pk %}{% else %}{{ file.canonical_url }}{% endif %}" ...

Searching for filer_image_expand_view in django-filer had no other occurences.

I made a quick and dirty dummy-test and everything worked as it should:

<a href="{% if 'svg' in file.mime_type %}{{ file.canonical_url }}{% else %}{{ file.canonical_url }}{% endif %}" ...

@fsbraun
Copy link
Member

fsbraun commented Jan 21, 2025

@0911R00 I believe this has been fixed in #1471 which was released in version 3.1.4 What version are you using? Can you upgrade?

@fsbraun
Copy link
Member

fsbraun commented Jan 21, 2025

@fabien-michel Yes, I can see that miscategorised files are a problem. A solution might be to catch errors here:

def get_admin_url(self, action):
return reverse(
'admin:{}_{}_{}'.format(
self._meta.app_label,
self._meta.model_name,
action
),
args=(self.pk,)
)

Putting that in a try-except block would avoid the crash. Additionaly, the buttons without liks should be disabled.

Can I encourage you to create a PR?

@0911R00
Copy link

0911R00 commented Jan 22, 2025

@0911R00 I believe this has been fixed in #1471 which was released in version 3.1.4 What version are you using? Can you upgrade?

Thanks! Works perfectly!

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

No branches or pull requests

4 participants