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

TransactWrite Commit Does Not Flush After _commit Method #1251

Open
jaeyoung0509 opened this issue Aug 12, 2024 · 0 comments
Open

TransactWrite Commit Does Not Flush After _commit Method #1251

jaeyoung0509 opened this issue Aug 12, 2024 · 0 comments

Comments

@jaeyoung0509
Copy link

  • First of all thanks to you I have been using it extensively in our production environment, and it has proven to be a very valuable tool

  • I frequently utilize the TransactWrite class for handling transactions.

  • However, I recently encountered an issue where, after invoking the _commit method, the transaction does not appear to flush the last items as expected. This behavior seems to cause problems when sharing the Connection object across different operations

  • Could you please clarify whether this is the intended behavior or if it might be a bug?

cf

  • pynamodb Transaction
class Transaction:

    """
    Base class for a type of transaction operation
    """

    def __init__(self, connection: Connection, return_consumed_capacity: Optional[str] = None) -> None:
        self._connection = connection
        self._return_consumed_capacity = return_consumed_capacity

    def _commit(self):
        raise NotImplementedError()

    def __enter__(self: _TTransaction) -> _TTransaction:
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type is None and exc_val is None and exc_tb is None:
            self._commit()
            # i think if the _commit is succeded  the transcation item should be flushed
  • pynamodb TransactWrite code
class TransactWrite(Transaction):

    def __init__(
        self,
        client_request_token: Optional[str] = None,
        return_item_collection_metrics: Optional[str] = None,
        **kwargs: Any,
    ) -> None:
        super(TransactWrite, self).__init__(**kwargs)
        self._client_request_token: Optional[str] = client_request_token
        self._return_item_collection_metrics = return_item_collection_metrics
        self._condition_check_items: List[Dict] = []
        self._delete_items: List[Dict] = []
        self._put_items: List[Dict] = []
        self._update_items: List[Dict] = []
        self._models_for_version_attribute_update: List[Any] = []



  def _commit(self) -> Any:
        response = self._connection.transact_write_items(
            condition_check_items=self._condition_check_items,
            delete_items=self._delete_items,
            put_items=self._put_items,
            update_items=self._update_items,
            client_request_token=self._client_request_token,
            return_consumed_capacity=self._return_consumed_capacity,
            return_item_collection_metrics=self._return_item_collection_metrics,
        )
        for model in self._models_for_version_attribute_update:
            model.update_local_version_attribute()
        return response
  • example code
global_dyn_connection = Connection()
transaction = TransactWrite(connection=global_dyn_connection)
def a():
    with transaction as tx:
        # do something


def b():
    with transaction as tx:
        # do something
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

1 participant