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

Allow use of firestore.transactional on instance methods #986

Open
andreas-thomik opened this issue Nov 21, 2024 · 0 comments
Open

Allow use of firestore.transactional on instance methods #986

andreas-thomik opened this issue Nov 21, 2024 · 0 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@andreas-thomik
Copy link

Is your feature request related to a problem? Please describe.
The current impementation of the @firestore.transactional decorator forces the transaction to be the first argument. This makes the wrapper unusable on methods which by design have self as their first argument.

Describe the solution you'd like
Ideally, the transaction object can be passed through keywords arguments. It should be possible to inspect the to_wrap function provided to check if a parameter named transaction exists. If not, fall back to the current implementation.

Describe alternatives you've considered
This can be worked around by using static methods, but makes for ugly code:

client = firestore.Client()

class MyClass:
    def __init__(self, a):
        self.a = a

    @staticmethod
    @firestore.transactional
    def _save_transactional(transaction, self):
        # Note: Not an actual "self" as normally understood in python code
        client.document("data/test").set({"a": self.a})
    
    def save(self):
        transaction = client.transaction()
        self._save_transactional(transaction, self)

Additional context
N/A

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Projects
None yet
Development

No branches or pull requests

3 participants