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 PatchNewCursor if created cursors use context __enter__ /__exit__ #147

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

polsala
Copy link
Member

@polsala polsala commented Nov 24, 2023

Poder usar PatchNewCursors con codigo que crea y usa nuevos cursores con el with

class TestPatchedCursors(testing.OOTestCase):
    def test_multiple_contexts(self):
        def magic(cursor, uid):
            import pooler
            with pooler.get_db_only(self.database).cursor() as _cr:
                pass
        user_obj = self.openerp.pool.get('res.users')
        setattr(user_obj, 'magic', magic)
        with Transaction().start(self.database) as txn:
            cursor = txn.cursor
            uid = txn.user
            with PatchNewCursors():
                user_obj.magic(cursor, uid)
2023-11-24 09:13:59,280:INFO:destral.testing.results:Traceback (most recent call last):
  File "/home/psala/Projects/erp/server/bin/addons/base/tests/__init__.py", line 47, in test_multiple_contexts
    user_obj.magic(cursor, uid)
  File "/home/psala/Projects/erp/server/bin/addons/base/tests/__init__.py", line 39, in magic
    with pooler.get_db_only(self.database).cursor() as _cr:
AttributeError: __exit__

@polsala polsala requested review from ecarreras and a team November 24, 2023 08:34
@polsala polsala self-assigned this Nov 24, 2023
@polsala polsala added patch Patch auto version V_._.X bug to be merged labels Nov 24, 2023
@ecarreras ecarreras merged commit 21f6c0a into master Nov 24, 2023
@ecarreras ecarreras deleted the add_context_manager_to_PatchedCursor branch November 24, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug patch Patch auto version V_._.X to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants