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

Problem when single quote is contained in resulting json assembled by rest interface (when querying indices) #83

Open
megies opened this issue Apr 12, 2018 · 0 comments
Labels

Comments

@megies
Copy link
Collaborator

megies commented Apr 12, 2018

There is a problem with Jane when querying the REST interface for document indices and the resulting json would contain a string that is enclosed by double quotes and contains a single quote it seems. Not sure if it's the problem of a specific dependency or why this problem has not surfaced before.

The error only shows up if the index for the offending document would be part of the query result. If it isn't, the REST query works as usual.

REST query: http://localhost:8000/rest/document_indices/quakeml?limit=1000&offset=89

Error traceback:

ImproperlyConfigured at /rest/document_indices/quakeml

Could not resolve URL for hyperlinked relationship using view name "rest_documents-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

Request Method: 	GET
Request URL: 	http://localhost:8000/rest/document_indices/quakeml?limit=1000&offset=89
Django Version: 	1.9.13
Exception Type: 	ImproperlyConfigured
Exception Value: 	

Could not resolve URL for hyperlinked relationship using view name "rest_documents-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

Exception Location: 	/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/relations.py in to_representation, line 393
Python Executable: 	/home/megies/anaconda/envs/jane-rotational/bin/python3
Python Version: 	3.6.5
Python Path: 	

['/home/megies/git/jane-rotational/src',
 '/home/megies/anaconda/envs/jane-rotational/lib/python36.zip',
 '/home/megies/anaconda/envs/jane-rotational/lib/python3.6',
 '/home/megies/anaconda/envs/jane-rotational/lib/python3.6/lib-dynload',
 '/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages',
 '/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/cycler-0.10.0-py3.6.egg',
 '/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/defusedxml-0.5.0-py3.6.egg']

Server time: 	Thu, 12 Apr 2018 14:31:54 +0000
full traceback
Environment:


Request Method: GET
Request URL: http://localhost:8000/rest/document_indices/quakeml?limit=1000&offset=89

Django Version: 1.9.13
Python Version: 3.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'djangoplugins',
 'rest_framework',
 'rest_framework_gis',
 'corsheaders',
 'debug_toolbar',
 'jane.jane',
 'jane.waveforms',
 'jane.documents',
 'jane.stationxml',
 'jane.quakeml',
 'jane.fdsnws']
Installed Middleware:
['django.middleware.gzip.GZipMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'jane.jane.middleware.AutoLogoutMiddleware']



Traceback:

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/relations.py" in to_representation
  378.             url = self.get_url(value, self.view_name, request, format)

File "/home/megies/git/jane-rotational/src/jane/documents/serializer.py" in get_url
  45.                            format=format)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/reverse.py" in reverse
  50.         url = _reverse(viewname, args, kwargs, request, format, **extra)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/reverse.py" in _reverse
  63.     url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/django/core/urlresolvers.py" in reverse
  600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

During handling of the above exception (Reverse for 'rest_documents-detail' with arguments '()' and keyword arguments '{'name': "GCMT_2007-08-26T134705Z_5.30_D'ENTRECASTEAUX_ISLANDS_REGION.xml", 'document_type': 'quakeml'}' not found. 1 pattern(s) tried: ['rest/documents/(?P<document_type>[a-zA-Z0-9]+)/(?P<name>[A-Za-z0-9-_.,:]+)/?$']), another exception occurred:

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/viewsets.py" in view
  90.             return self.dispatch(request, *args, **kwargs)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
  489.             response = self.handle_exception(exc)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception
  449.             self.raise_uncaught_exception(exc)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
  486.             response = handler(request, *args, **kwargs)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/mixins.py" in list
  45.             return self.get_paginated_response(serializer.data)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/serializers.py" in data
  739.         ret = super(ListSerializer, self).data

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/serializers.py" in data
  263.                 self._data = self.to_representation(self.instance)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/serializers.py" in to_representation
  657.             self.child.to_representation(item) for item in iterable

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/serializers.py" in <listcomp>
  657.             self.child.to_representation(item) for item in iterable

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/serializers.py" in to_representation
  501.                 ret[field.field_name] = field.to_representation(attribute)

File "/home/megies/anaconda/envs/jane-rotational/lib/python3.6/site-packages/rest_framework/relations.py" in to_representation
  393.             raise ImproperlyConfigured(msg % self.view_name)

Exception Type: ImproperlyConfigured at /rest/document_indices/quakeml
Exception Value: Could not resolve URL for hyperlinked relationship using view name "rest_documents-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

This is the file that was causing the problem:
GCMT_2015-07-14T021007Z_4.90_D'ENTRECASTEAUX_ISLANDS_REGION.xml.zip

conda env info
# packages in environment at /home/megies/anaconda/envs/jane-rotational:
#
# Name                    Version                   Build  Channel
asn1crypto                0.24.0                   py36_0    conda-forge
boost                     1.66.0                   py36_1    conda-forge
boost-cpp                 1.66.0                        1    conda-forge
bzip2                     1.0.6                         1    conda-forge
ca-certificates           2018.1.18                     0    conda-forge
cairo                     1.14.10                       0    conda-forge
certifi                   2018.1.18                py36_0    conda-forge
cffi                      1.11.5                   py36_0    conda-forge
chardet                   3.0.4                    py36_0    conda-forge
click                     6.7                        py_1    conda-forge
cryptography              2.2.1                    py36_0    conda-forge
curl                      7.59.0                        1    conda-forge
cycler                    0.10.0                   py36_0    conda-forge
dbus                      1.10.22                       0    conda-forge
decorator                 4.2.1                    py36_0    conda-forge
defusedxml                0.5.0                    py36_0    conda-forge
django                    1.9.13                   py36_0    conda-forge
django-cors-headers       2.2.0                     <pip>
django-debug-toolbar      1.9.1                      py_0    conda-forge
django-dirtyfields        1.3.1                     <pip>
django-plugins            0.3.0                     <pip>
djangorestframework       3.6.4                      py_0    conda-forge
djangorestframework-gis   0.12                       py_0    conda-forge
djangorestframework-jsonp 1.0.2                     <pip>
djangorestframework-xml   1.3.0                      py_0    conda-forge
djangorestframework-yaml  1.0.3                      py_0    conda-forge
expat                     2.2.5                         0    conda-forge
flake8                    3.5.0                    py36_0    conda-forge
fontconfig                2.12.6                        0    conda-forge
freetype                  2.8.1                         0    conda-forge
freexl                    1.0.5                         0    conda-forge
future                    0.16.0                   py36_0    conda-forge
gdal                      2.2.4                    py36_0    conda-forge
geojson                   2.3.0                      py_0    conda-forge
geopy                     1.12.0                     py_0    conda-forge
geos                      3.6.2                         1    conda-forge
geotiff                   1.4.2                         1    conda-forge
gettext                   0.19.8.1                      0    conda-forge
giflib                    5.1.4                         0    conda-forge
glib                      2.55.0                        0    conda-forge
gst-plugins-base          1.8.0                         0    conda-forge
gstreamer                 1.8.0                         1    conda-forge
hdf4                      4.2.13                        0    conda-forge
hdf5                      1.10.1                        2    conda-forge
icu                       58.2                          0    conda-forge
idna                      2.6                      py36_1    conda-forge
intel-openmp              2018.0.0                      8  
jinja2                    2.10                     py36_0    conda-forge
jpeg                      9b                            2    conda-forge
json-c                    0.12.1                        0    conda-forge
kealib                    1.4.7                         4    conda-forge
kiwisolver                1.0.1                    py36_1    conda-forge
krb5                      1.14.6                        0    conda-forge
libdap4                   3.18.3                        2    conda-forge
libffi                    3.2.1                         3    conda-forge
libgcc-ng                 7.2.0                hdf63c60_3  
libgdal                   2.2.4                         1    conda-forge
libgfortran               3.0.0                         1  
libgfortran-ng            7.2.0                hdf63c60_3  
libiconv                  1.15                          0    conda-forge
libkml                    1.3.0                         6    conda-forge
libnetcdf                 4.5.0                         3    conda-forge
libpng                    1.6.34                        0    conda-forge
libpq                     9.6.3                         0    conda-forge
libspatialite             4.3.0a                       19    conda-forge
libssh2                   1.8.0                         2    conda-forge
libstdcxx-ng              7.2.0                hdf63c60_3  
libtiff                   4.0.9                         0    conda-forge
libxcb                    1.13                          0    conda-forge
libxml2                   2.9.8                         0    conda-forge
libxslt                   1.1.32                        0    conda-forge
livereload                2.5.1                    py36_0    conda-forge
lxml                      4.2.1                    py36_0    conda-forge
markdown                  2.6.11                     py_0    conda-forge
markupsafe                1.0                      py36_0    conda-forge
matplotlib                2.2.2                    py36_1    conda-forge
mccabe                    0.6.1                    py36_0    conda-forge
mkdocs                    0.17.3                     py_0    conda-forge
mkdocs-bootswatch         0.5.0                      py_0    conda-forge
mkl                       2018.0.2                      1  
mkl_fft                   1.0.1                    py36_1    conda-forge
mkl_random                1.0.1                    py36_0    conda-forge
ncurses                   5.9                          10    conda-forge
numpy                     1.14.2           py36hdbf6ddf_1  
obspy                     1.1.0                    py36_1    conda-forge
openjpeg                  2.3.0                         2    conda-forge
openssl                   1.0.2n                        0    conda-forge
pcre                      8.41                          1    conda-forge
pip                       9.0.3                    py36_0    conda-forge
pixman                    0.34.0                        1    conda-forge
poppler                   0.61.1                        3    conda-forge
poppler-data              0.4.8                         0    conda-forge
proj4                     4.9.3                         5    conda-forge
psycopg2                  2.7.4                    py36_0    conda-forge
pycodestyle               2.3.1                    py36_0    conda-forge
pycparser                 2.18                     py36_0    conda-forge
pyflakes                  1.6.0                    py36_0    conda-forge
pyopenssl                 17.5.0                   py36_1    conda-forge
pyparsing                 2.2.0                    py36_0    conda-forge
pyqt                      5.6.0                    py36_4    conda-forge
pysocks                   1.6.8                    py36_1    conda-forge
python                    3.6.5                         1    conda-forge
python-dateutil           2.7.2                      py_0    conda-forge
pytz                      2018.4                     py_0    conda-forge
pyyaml                    3.12                     py36_1    conda-forge
qt                        5.6.2                         7    conda-forge
readline                  7.0                           0    conda-forge
requests                  2.18.4                   py36_1    conda-forge
scipy                     1.0.1            py36hfc37229_0  
setuptools                39.0.1                   py36_0    conda-forge
sip                       4.18                     py36_1    conda-forge
six                       1.11.0                   py36_1    conda-forge
sqlalchemy                1.2.6                    py36_0    conda-forge
sqlite                    3.20.1                        2    conda-forge
sqlparse                  0.2.4                      py_0    conda-forge
tk                        8.6.7                         0    conda-forge
tornado                   5.0.2                    py36_0    conda-forge
urllib3                   1.22                     py36_0    conda-forge
util-linux                2.21                          0  
wheel                     0.31.0                   py36_0    conda-forge
xerces-c                  3.2.0                         0    conda-forge
xorg-libxau               1.0.8                         3    conda-forge
xorg-libxdmcp             1.1.2                         3    conda-forge
xz                        5.2.3                         0    conda-forge
yaml                      0.1.7                         0    conda-forge
zlib                      1.2.11                        0    conda-forge
@megies megies added the bug label Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant