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

Too small field length restrictions on models.FileField #86

Open
pouldenton opened this issue Dec 9, 2022 · 2 comments
Open

Too small field length restrictions on models.FileField #86

pouldenton opened this issue Dec 9, 2022 · 2 comments

Comments

@pouldenton
Copy link
Contributor

Hello!
By default Django models.FileField is limited to 100 chars.
In some cases this limit is too small for payload fields in Mdn and Message tables.
This cause problems with long filenames (update query fails and field left blank) and prevent normal message/mdn view and mdn sending:

ValueError: The 'payload' attribute has no file associated with it.
Internal Server Error: /admin/pyas2/mdn/290276/change/

Sending all pending asynchronous MDNs
Traceback (most recent call last):
File "/var/www/pyas2/manage.py", line 22, in
main()
File "/var/www/pyas2/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/init.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/pyas2/management/commands/manageas2server.py", line 125, in handle
data=pending_mdn.payload.read(),
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/files/utils.py", line 42, in
read = property(lambda self: self.file.read)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/db/models/fields/files.py", line 43, in _get_file
self._require_file()
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/db/models/fields/files.py", line 40, in _require_file
raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'payload' attribute has no file associated with it.

Seems like maximum full path length on various filesystems is about 4096 characters.

I propose to set max_length for payload fields in pyas2/models.py to 4096 like this:

payload = models.FileField(upload_to=get_mdn_store, null=True, blank=True, max_length=4096)

payload = models.FileField(upload_to=get_message_store, null=True, blank=True, max_length=4096)

@abhishek-ram
Copy link
Owner

makes sense, can you open a PR

@pouldenton
Copy link
Contributor Author

PR #87 opened

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

2 participants