0001-add-django-request-context-to-requests-error-logs-33.patch
combo/data/models.py | ||
---|---|---|
1146 | 1146 |
invalidate_cache=invalidate_cache, |
1147 | 1147 |
log_errors=log_errors, |
1148 | 1148 |
timeout=data_url_dict.get('timeout', self.timeout), |
1149 |
django_request=context.get('request'), |
|
1149 | 1150 |
) |
1150 | 1151 |
except requests.RequestException as e: |
1151 | 1152 |
extra_context[data_key + '_status'] = -1 |
... | ... | |
1237 | 1238 |
headers={'Accept': 'application/json'}, |
1238 | 1239 |
remote_service='auto', |
1239 | 1240 |
json=content, |
1240 |
without_user=True) |
|
1241 |
without_user=True, |
|
1242 |
django_request=request, |
|
1243 |
) |
|
1241 | 1244 | |
1242 | 1245 |
if json_response.status_code // 100 != 2: # 2xx |
1243 | 1246 |
logger.error('error POSTing data to URL (%s)', url) |
combo/utils/requests_wrapper.py | ||
---|---|---|
39 | 39 |
cache_duration = kwargs.pop('cache_duration', 15) |
40 | 40 |
invalidate_cache = kwargs.pop('invalidate_cache', False) |
41 | 41 |
user = kwargs.pop('user', None) |
42 |
django_request = kwargs.pop('django_reqeuest', None) |
|
42 | 43 |
without_user = kwargs.pop('without_user', False) |
43 | 44 |
federation_key = kwargs.pop('federation_key', 'auto') # 'auto', 'email', 'nameid' |
44 | 45 |
raise_if_not_cached = kwargs.pop('raise_if_not_cached', False) |
... | ... | |
123 | 124 | |
124 | 125 |
response = super(Requests, self).request(method, url, **kwargs) |
125 | 126 |
if log_errors and (response.status_code // 100 != 2): |
126 |
logging.error('failed to %s %s (%s)', method, url, response.status_code) |
|
127 |
extra = {} |
|
128 |
if django_request: |
|
129 |
extra['request'] = django_request |
|
130 |
logging.error('failed to %s %s (%s)', method, url, response.status_code, extra=extra) |
|
127 | 131 |
if method == 'GET' and cache_duration and (response.status_code // 100 == 2): |
128 | 132 |
cache.set(cache_key, response.content, cache_duration) |
129 | 133 | |
130 |
- |