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

Migrating existing files failing #30

Open
jonadeline opened this issue May 21, 2020 · 2 comments
Open

Migrating existing files failing #30

jonadeline opened this issue May 21, 2020 · 2 comments

Comments

@jonadeline
Copy link

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
Copy link
Member

Which frappe version are you using?

@jonadeline
Copy link
Author

jonadeline commented May 31, 2020

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

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