Skip to content
This repository was archived by the owner on Apr 27, 2021. It is now read-only.

Commit 2469be4

Browse files
committed
add a way to clone/update a profile
PYTHON-569
1 parent d5379e7 commit 2469be4

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

cassandra/cluster.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import atexit
2222
from collections import defaultdict, Mapping
2323
from concurrent.futures import ThreadPoolExecutor, wait as wait_futures
24+
from copy import copy
2425
import logging
2526
from random import random
2627
import socket
@@ -2062,6 +2063,21 @@ def _get_execution_profile(self, ep):
20622063
except KeyError:
20632064
raise ValueError("Invalid execution_profile: '%s'; valid profiles are %s" % (ep, profiles.keys()))
20642065

2066+
def execution_profile_clone_update(self, ep, **kwargs):
2067+
"""
2068+
Returns a clone of the ``ep`` profile. ``kwargs`` can be specified to update attributes
2069+
of the returned profile.
2070+
2071+
This is a shollow clone, so any objects referenced by the profile are shared. This means Load Balancing Policy
2072+
is maintained by inclusion in the active profiles. It also means updating any other rich objects will be seen
2073+
by the active profile. In cases where this is not desirable, be sure to replace the instance instead of manipulating
2074+
the shared object.
2075+
"""
2076+
clone = copy(self._get_execution_profile(ep))
2077+
for attr, value in kwargs.items():
2078+
setattr(clone, attr, value)
2079+
return clone
2080+
20652081
def prepare(self, query, custom_payload=None):
20662082
"""
20672083
Prepares a query string, returning a :class:`~cassandra.query.PreparedStatement`

docs/api/cassandra/cluster.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146

147147
.. automethod:: set_keyspace(keyspace)
148148

149+
.. automethod:: execution_profile_clone_update
150+
149151
.. autoclass:: ResponseFuture ()
150152

151153
.. autoattribute:: query

0 commit comments

Comments
 (0)