aschn / drf-tracking

Utils to track requests to Django Rest Framework API views
http://drf-tracking.readthedocs.org/
ISC License
366 stars 95 forks source link

Azure proxy config throws psycopg2 exception #150

Open drdreff opened 4 years ago

drdreff commented 4 years ago

I'd really like to figure out a workaround for this issue. I'll put what I find here for others.

2020-03-10T14:59:03.135990572Z Logging API call raise exception!
2020-03-10T14:59:03.136026572Z Traceback (most recent call last):
2020-03-10T14:59:03.136032272Z   File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
2020-03-10T14:59:03.136036372Z     return self.cursor.execute(sql, params)
2020-03-10T14:59:03.136040272Z psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type inet: "24.23.134.119:43398"
2020-03-10T14:59:03.136044372Z LINE 1: ...e/', 'portola.views.DocumentViewSet', 'disclose', '24.23.134...
2020-03-10T14:59:03.136048272Z                                                              ^
2020-03-10T14:59:03.136052072Z
2020-03-10T14:59:03.136055472Z
2020-03-10T14:59:03.136058972Z The above exception was the direct cause of the following exception:
2020-03-10T14:59:03.136062672Z
2020-03-10T14:59:03.136066171Z Traceback (most recent call last):
2020-03-10T14:59:03.136069771Z   File "/antenv/lib/python3.7/site-packages/rest_framework_tracking/base_mixins.py", line 78, in finalize_response
2020-03-10T14:59:03.136073671Z     self.handle_log()
2020-03-10T14:59:03.136089071Z   File "/antenv/lib/python3.7/site-packages/rest_framework_tracking/mixins.py", line 12, in handle_log
2020-03-10T14:59:03.136093371Z     APIRequestLog(**self.log).save()
2020-03-10T14:59:03.136096871Z   File "/antenv/lib/python3.7/site-packages/django/db/models/base.py", line 741, in save
2020-03-10T14:59:03.136100571Z     force_update=force_update, update_fields=update_fields)
2020-03-10T14:59:03.136105271Z   File "/antenv/lib/python3.7/site-packages/django/db/models/base.py", line 779, in save_base
2020-03-10T14:59:03.136108971Z     force_update, using, update_fields,
2020-03-10T14:59:03.136112371Z   File "/antenv/lib/python3.7/site-packages/django/db/models/base.py", line 870, in _save_table
2020-03-10T14:59:03.136115971Z     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
2020-03-10T14:59:03.136119571Z   File "/antenv/lib/python3.7/site-packages/django/db/models/base.py", line 908, in _do_insert
2020-03-10T14:59:03.136123271Z     using=using, raw=raw)
2020-03-10T14:59:03.136126671Z   File "/antenv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
2020-03-10T14:59:03.136130371Z     return getattr(self.get_queryset(), name)(*args, **kwargs)
2020-03-10T14:59:03.136133871Z   File "/antenv/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _insert
2020-03-10T14:59:03.136137471Z     return query.get_compiler(using=using).execute_sql(return_id)
2020-03-10T14:59:03.136140971Z   File "/antenv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1335, in execute_sql
2020-03-10T14:59:03.136144671Z     cursor.execute(sql, params)
2020-03-10T14:59:03.136148071Z   File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
2020-03-10T14:59:03.136152571Z     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
2020-03-10T14:59:03.136156271Z   File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
2020-03-10T14:59:03.136159871Z     return executor(sql, params, many, context)
2020-03-10T14:59:03.136163371Z   File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
2020-03-10T14:59:03.136166971Z     return self.cursor.execute(sql, params)
2020-03-10T14:59:03.136170371Z   File "/antenv/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
2020-03-10T14:59:03.136173971Z     raise dj_exc_value.with_traceback(traceback) from exc_value
2020-03-10T14:59:03.136177471Z   File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
2020-03-10T14:59:03.136181071Z     return self.cursor.execute(sql, params)
2020-03-10T14:59:03.136184471Z django.db.utils.DataError: invalid input syntax for type inet: "24.23.134.119:43398"
2020-03-10T14:59:03.136188171Z LINE 1: ...e/', 'portola.views.DocumentViewSet', 'disclose', '24.23.134...
2020-03-10T14:59:03.136194471Z                                                              ^
2020-03-10T14:59:03.136198171Z
lingster commented 4 years ago

is it because "24.23.134.119:43398" is not a valid internet address? Perhaps it should be: "24.23.134.119" ?

drdreff commented 4 years ago

That string is invalid, yes. I'm trying to trace back where in the proxy configuration the port number (43398) is being added. I'm not sure if the fix belongs in drf-tracking or ... ? The symptom is that drf-tracking somewhat silently fails.

lingster commented 4 years ago

Just to let you know that this project has moved over to: https://github.com/lingster/drf-api-tracking as the original owner does not appear to be maintaining this. If you'd like me to take a deeper dive, can you raise an issue in the new repo?

The stack trace does point to an issue with drf-tracking. Do you have details of the request and query string that you could share to help reproduce the issue?

drdreff commented 4 years ago

I will try to create a good test since I've only been getting this in Azure. I'l also head over to the new project

MD

lingster commented 4 years ago

Ok great, we're holding an online sprint(https://www.meetup.com/Python-Sprints/events/269207483/) to hopefully address some of the issues in the drf-api-tracking project. If you get your test ready before monday, then I'm sure there maybe some able to help resolve the issue.

drdreff commented 4 years ago

please let me know what other help I can provide to help address this. I'd love to find a solution or workaround.