zerodha / frappe-attachments-s3

A frappe app to upload file attachments in doctypes to s3.
Other
115 stars 131 forks source link

Migrating existing files failing #30

Open jonadeline opened 4 years ago

jonadeline commented 4 years ago

Expected behaviour

Import all existing attachments to S3

Actual behaviour

Error message

Step to reproduce

Click "Migrating existing files" button

Version

Latest

image

Traceback (most recent call last):

  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 61, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1042, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe_s3_attachment/frappe_s3_attachment/controller.py", line 294, in migrate_existing_files
    upload_existing_files_s3(file['name'], file['file_name'])
  File "/home/frappe/frappe-bench/apps/frappe_s3_attachment/frappe_s3_attachment/controller.py", line 250, in upload_existing_files_s3
    parent_name
  File "/home/frappe/frappe-bench/apps/frappe_s3_attachment/frappe_s3_attachment/controller.py", line 98, in upload_files_to_s3_with_key
    key = self.key_generator(file_name, parent_doctype, parent_name)
  File "/home/frappe/frappe-bench/apps/frappe_s3_attachment/frappe_s3_attachment/controller.py", line 80, in key_generator
    "/" + day + "/" + parent_doctype + "/" + key + "_" + \
TypeError: must be str, not NoneType
shridarpatil commented 4 years ago

Which frappe version are you using?

jonadeline commented 4 years ago

I'm on version 12. But I think I figured out what was wrong. It was missing some check in the key_generator function regarding the docType. That is said I simplified this function as I just wanted my files to be uploaded at the root of my bucket so I ended up with this :

 def key_generator(self, file_name, parent_doctype, parent_name):
        """
        Generate keys for s3 objects uploaded with file name attached.
        """
        file_name = file_name.replace(' ', '_')
        file_name = self.strip_special_chars(file_name)
        key = ''.join(
            random.choice(
                string.ascii_uppercase + string.digits) for _ in range(8)
        )
       final_key = key + "_" + file_name
       return final_key