Skip to content

fix: File upload failed#2398

Merged
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_file_upload
Feb 25, 2025
Merged

fix: File upload failed#2398
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_file_upload

Conversation

@shaohuzhang1
Copy link
Contributor

fix: File upload failed

@shaohuzhang1 shaohuzhang1 merged commit fdb2cbd into main Feb 25, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_file_upload branch February 25, 2025 09:02
meta = serializers.JSONField(required=False, allow_null=True)

def upload(self, with_valid=True):
if with_valid:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one issue and an optimization suggestion in the provided code:

Issue: In the __init__ method, you have defined a variable called _meta, but it seems like there might be confusion about its intended use. It's not clear whether this is supposed to be used internally within the class or as a property that should be accessible from outside.

Suggested Optimization: Use an underscore convention only for private variables inside a class, which helps maintain clean code organization without affecting readability. You can also streamline the logic by removing unnecessary comments or empty lines.

class FileSerializer(BaseSerializer):  # Assuming BaseSerializer is imported somewhere else
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._meta = None

    file = UploadedFileField(required=True,
                               error_messages=getattr(self.Meta, 'error_messages',
                                                     ErrMessage.image(_('file'))))

    meta = serializers.JSONField(required=False, allow_null=True)

    def upload(self, with_valid=True):
        if with_valid:
            # Your implementation here...

This version of the code addresses both the potential confusion with underscores and improves consistency in naming conventions, making it easier for other developers to understand and work with.

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

Successfully merging this pull request may close these issues.

1 participant