You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/06/03 15:42:49 UTC
[GitHub] [skywalking-python] tom-pytel opened a new pull request, #211: fix sw_psycopg2 register_type()
tom-pytel opened a new pull request, #211:
URL: https://github.com/apache/skywalking-python/pull/211
`psycopg2._psycopg.register_type()` can be called with a connection or cursor, but since these are wrapped proxy objects when instrumented the binary module `_psycopg` does not recognize them causing calls like `psycopg2.extras.register_json()` to fail:
```
...
File "/usr/local/lib/python3.10/site-packages/psycopg2/_json.py", line 120, in register_json
register_type(JSON, not globally and conn_or_curs or None)
TypeError: argument 2 must be a connection, cursor or None
```
The fix is simply to pass unwrapped connection or cursor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] Superskyyy merged pull request #211: Fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
Superskyyy merged PR #211:
URL: https://github.com/apache/skywalking-python/pull/211
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] tom-pytel commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
tom-pytel commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146158898
> > > This addresses this [apache/skywalking#8556](https://github.com/apache/skywalking/discussions/8556) problem, right? Thanks for looking into this.
> >
> >
> > Should, yes.
>
> If you have verified it works for Django version above 3.10 then LGTM. :)
There is a Django 3.10? I did do a quick test of our fork of this with Django 4.0.5 and it works, waiting on more thorough tests from the test monkeys though.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] Superskyyy commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
Superskyyy commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146147524
> > This addresses this [apache/skywalking#8556](https://github.com/apache/skywalking/discussions/8556) problem, right? Thanks for looking into this.
>
> Should, yes.
If you have verified it works for Django version above 3.10 then LGTM. :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] tom-pytel commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
tom-pytel commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146187121
> LOL I forgot Django is already at 4.x. Btw we should bump up the checked versions in Django plugin supported matrix.
That is for a different PR, this one is about psycopg2.
> BTW, do you think we should remove the support for 3.6? It has been sunsetted since 6 months ago. We will introduce some advanced features requiring 3.7 up, like the automatic post-fork hook.
If you are asking my opinion then don't remove support for something until and unless you need to. There's nothing worse than having your project stop working for no good reason other than an arbitrary date.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] tom-pytel commented on a diff in pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
tom-pytel commented on code in PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#discussion_r889070603
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
Review Comment:
ignore
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] Superskyyy commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
Superskyyy commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146168385
> > > > This addresses this [apache/skywalking#8556](https://github.com/apache/skywalking/discussions/8556) problem, right? Thanks for looking into this.
> > >
> > >
> > > Should, yes.
> >
> >
> > If you have verified it works for Django version above 3.10 then LGTM. :)
>
> There is a Django 3.10? I did do a quick test of our fork of this with Django 4.0.5 and it works, waiting on more thorough tests from the test monkeys though.
LOL I forgot Django is already at 4.x. Btw we should bump up the checked versions in plugin supported matrix.
```
support_matrix = {
'django': {
'>=3.6': ['3.2'],
# ">=3.8": ["4.0a1"] # expected Dec 2021
}
}
``` change to something like
```
support_matrix = {
'django': {
'>=3.6': ['3.2'],
">=3.8': ['4.0'] # 4.2 will support py3.11
}
}
```
BTW, do you think we should remove the support for 3.6? It has been sunsetted since 6 months ago. We will introduce some advanced features requiring 3.7 up, like the automatic post-fork hook.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] sonatype-lift[bot] commented on a diff in pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#discussion_r889065176
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
Review Comment:
*try_except_pass:* Try, Except, Pass detected.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
---
Was this a good recommendation?
[ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=263686957&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=263686957&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686957&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686957&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=263686957&lift_comment_rating=5) ]
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._json.register_type is _register_type:
+ psycopg2._json.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._range.register_type is _register_type:
+ psycopg2._range.register_type = register_type
+
+ except Exception:
Review Comment:
*try_except_pass:* Try, Except, Pass detected.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
---
Was this a good recommendation?
[ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=263686959&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=263686959&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686959&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686959&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=263686959&lift_comment_rating=5) ]
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._json.register_type is _register_type:
+ psycopg2._json.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._range.register_type is _register_type:
+ psycopg2._range.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2.extensions.register_type is _register_type:
+ psycopg2.extensions.register_type = register_type
+
+ except Exception:
+ pass
+
+ except Exception:
Review Comment:
*try_except_pass:* Try, Except, Pass detected.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
---
Was this a good recommendation?
[ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=263686961&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=263686961&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686961&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686961&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=263686961&lift_comment_rating=5) ]
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._json.register_type is _register_type:
+ psycopg2._json.register_type = register_type
+
+ except Exception:
Review Comment:
*try_except_pass:* Try, Except, Pass detected.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
---
Was this a good recommendation?
[ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=263686958&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=263686958&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686958&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686958&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=263686958&lift_comment_rating=5) ]
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._json.register_type is _register_type:
+ psycopg2._json.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._range.register_type is _register_type:
+ psycopg2._range.register_type = register_type
+
+ except Exception:
+ pass
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2.extensions.register_type is _register_type:
+ psycopg2.extensions.register_type = register_type
+
+ except Exception:
Review Comment:
*try_except_pass:* Try, Except, Pass detected.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
---
Was this a good recommendation?
[ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=263686960&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=263686960&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686960&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=263686960&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=263686960&lift_comment_rating=5) ]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] tom-pytel commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
tom-pytel commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146144139
> This addresses this [apache/skywalking#8556](https://github.com/apache/skywalking/discussions/8556) problem, right? Thanks for looking into this.
Should, yes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] Superskyyy commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
Superskyyy commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146100563
This addresses this https://github.com/apache/skywalking/discussions/8556 problem, right? Thanks for looking into this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] Superskyyy commented on pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
Superskyyy commented on PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#issuecomment-1146234955
> That is for a different PR, this one is about psycopg2.
>
> If you are asking my opinion then don't remove support for something until and unless you need to. There's nothing worse than having your project stop working for no good reason other than an arbitrary date.
Yes, thanks for the explanation. LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-python] sonatype-lift[bot] commented on a diff in pull request #211: fix sw_psycopg2 register_type()
Posted by GitBox <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #211:
URL: https://github.com/apache/skywalking-python/pull/211#discussion_r889070656
##########
skywalking/plugins/sw_psycopg2.py:
##########
@@ -128,3 +128,53 @@ def connect(*args, **kwargs):
_connect = psycopg2.connect
psycopg2.connect = connect
+
+ try: # try to instrument register_type which will fail if it gets a wrapped cursor or connection
+ from psycopg2._psycopg import register_type as _register_type
+
+ def register_type(c, conn_or_curs):
+ if isinstance(conn_or_curs, ProxyConnection):
+ conn_or_curs = conn_or_curs._self_conn
+ elif isinstance(conn_or_curs, ProxyCursor):
+ conn_or_curs = conn_or_curs._self_cur
+
+ return _register_type(c, conn_or_curs)
+
+ try:
+ import psycopg2._ipaddress
+
+ if psycopg2._ipaddress.register_type is _register_type:
+ psycopg2._ipaddress.register_type = register_type
+
+ except Exception:
Review Comment:
I've recorded this as ignored for this pull request. If you change your mind, just comment `@sonatype-lift unignore`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org