abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
78 stars 31 forks source link

Too small field length restrictions on models.FileField #86

Open pouldenton opened 1 year ago

pouldenton commented 1 year ago

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 commented 1 year ago

makes sense, can you open a PR

pouldenton commented 1 year ago

PR #87 opened