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

fix BulkWriter.__init__ bug when it has object_class param input #1107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hagd0520
Copy link

fix bug occur to two scenarios

  • Initialize BulkWriter directly by BulkWriter.init with object_class parm input.
  • Initialize BulkWriter through Document.bulk_writer and Document has collection.

@hagd0520 hagd0520 changed the title fix: fix BulkWriter.__init__ bug when it has object_class param input fix BulkWriter.__init__ bug when it has object_class param input Jan 14, 2025
@CAPITAINMARVEL
Copy link
Contributor

fix bug occur to two scenarios

  • Initialize BulkWriter directly by BulkWriter.init with object_class parm input.
  • Initialize BulkWriter through Document.bulk_writer and Document has collection.

the collection name is only used when add_operation is called and doesnt alter anything as long object_class is not none when you commit

@hagd0520 hagd0520 closed this Jan 31, 2025
@hagd0520 hagd0520 reopened this Jan 31, 2025
@hagd0520
Copy link
Author

fix bug occur to two scenarios

  • Initialize BulkWriter directly by BulkWriter.init with object_class parm input.
  • Initialize BulkWriter through Document.bulk_writer and Document has collection.

the collection name is only used when add_operation is called and doesnt alter anything as long object_class is not none when you commit

bug appears from the add_operation func.

    def add_operation(
        self,
        object_class: Type[Union[Document, UnionDoc]],
        operation: _WriteOp,
    ):
        if self.object_class is None:
            self.object_class = object_class
            self._collection_name = object_class.get_collection_name()
        else:
            if object_class.get_collection_name() != self._collection_name:
                raise ValueError(
                    "All the operations should be for a same collection name"
                )
        self.operations.append(operation)

under the scenarios i mentioned, initialized BulkWriter has no _collections_name and it raise the ValueError from the line 154 in bulk.py cause its object_class is not None and _collections_name is None.

so that _collections_name should be properly intialized.

@CAPITAINMARVEL
Copy link
Contributor

fix bug occur to two scenarios

  • Initialize BulkWriter directly by BulkWriter.init with object_class parm input.
  • Initialize BulkWriter through Document.bulk_writer and Document has collection.

the collection name is only used when add_operation is called and doesnt alter anything as long object_class is not none when you commit

bug appears from the add_operation func.

    def add_operation(
        self,
        object_class: Type[Union[Document, UnionDoc]],
        operation: _WriteOp,
    ):
        if self.object_class is None:
            self.object_class = object_class
            self._collection_name = object_class.get_collection_name()
        else:
            if object_class.get_collection_name() != self._collection_name:
                raise ValueError(
                    "All the operations should be for a same collection name"
                )
        self.operations.append(operation)

under the scenarios i mentioned, initialized BulkWriter has no _collections_name and it raise the ValueError from the line 154 in bulk.py cause its object_class is not None and _collections_name is None.

so that _collections_name should be properly intialized.

oh I see what you means now

@CAPITAINMARVEL CAPITAINMARVEL requested a review from a team January 31, 2025 19:11
Copy link
Contributor

@CAPITAINMARVEL CAPITAINMARVEL left a comment

Choose a reason for hiding this comment

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

lgtm

@staticxterm staticxterm requested a review from a team February 1, 2025 21:07
@staticxterm staticxterm requested a review from a team February 1, 2025 21:08
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.

3 participants