Skip to content

Conversation

@pglombardo
Copy link
Contributor

@pglombardo pglombardo commented Dec 11, 2019

running this wrapper-

@wrapt.patch_function_wrapper('psycopg2.extensions', 'register_type')
    def register_type_with_instana(wrapped, instance, args, kwargs):
        args_clone = list(copy.copy(args))

        if (len(args_clone) >= 2) and hasattr(args_clone[1], '__wrapped__'):
            args_clone[1] = args_clone[1].__wrapped__

        return wrapped(*args_clone, **kwargs)

Is causing an error to be thrown here psycopg2/_json.py:

def register_json(conn_or_curs=None, globally=False, loads=None,
                  oid=None, array_oid=None, name='json'):
    if oid is None:
        oid, array_oid = _get_json_oids(conn_or_curs, name)

    JSON, JSONARRAY = _create_json_typecasters(
        oid, array_oid, loads=loads, name=name.upper())

    register_type(JSON, not globally and conn_or_curs or None) . <--------- argument 2 must be a connection, cursor or None

    if JSONARRAY is not None:
        register_type(JSONARRAY, not globally and conn_or_curs or None)

    return JSON, JSONARRAY

@bman7777 bman7777 changed the title Psycopg2 instrumentation breaks aiopg json registration Psycopg2 instrumentation breaks psycopg2 json registration (in aiohttp) Dec 6, 2019
@bman7777 bman7777 changed the title Psycopg2 instrumentation breaks psycopg2 json registration (in aiohttp) Psycopg2 instrumentation breaks json registration (in aiohttp) Dec 6, 2019
@pglombardo
Copy link
Contributor

Hi @bman7777 - thanks for letting us know. We had one other report of this but I haven't been able to reproduce this. Could you share the psycopg2 calls that are triggering this in your application?

Also is it on application boot or during request handling?

The above would help but in either case, I'll aim to get a fix out soon.

@bman7777
Copy link
Author

bman7777 commented Dec 6, 2019

This is on boot. Sure I can share the callstack-

psycopg2/_json.py in register_json at line 124
psycopg2/_json.py in register_default_json at line 142
aiopg/connection.py in _connect at line 83
aiopg/utils.py in __iter__ at line 66
aiopg/pool.py in _fill_free_pool at line 208
aiopg/pool.py in _create_pool at line 47
aiopg/utils.py in __await__ at line 71
top call ---->  await aiopg.create_pool(dsn, minsize=10, maxsize=100, timeout=10)

My aiopg version is: 0.16.0

@pglombardo pglombardo merged commit a8706ff into master Dec 11, 2019
@pglombardo pglombardo deleted the aiopg-and-psycopg2 branch December 11, 2019 14:21
@pglombardo
Copy link
Contributor

This has been fixed and released in Instana package 1.17.2. Thanks again @bman7777!

@bman7777
Copy link
Author

Thanks!!

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

Successfully merging this pull request may close these issues.

3 participants