Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1771

Add args/kwargs support to ClientSession.with_transaction()

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API
    • None

      In PYTHON-1671, we discussed whether to support passing arbitrary arguments to the callback like this:

      def callback(session, custom_arg, custom_kwarg=None):
          # Transaction operations...
      
      with client.start_session() as session:
          ret = session.with_transaction(
              callback, args=('custom_arg',), kwargs=dict(custom_kwarg=10))
      

      This args/kwargs API matches the standard library's API for threading.Thread and multiprocessing.Process.

      However, we opted to not add support for this because there is an easy alternative; using a lambda like this:

      with client.start_session() as session:
          ret = session.with_transaction(
              lambda s: callback(s, 'custom_arg', custom_kwarg=10))
      

      We also wanted to get feedback from real users before adding more options to the API.

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: