Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Enum schema are not decoded #122

Closed
sebastibe opened this issue Mar 12, 2017 · 8 comments
Closed

Enum schema are not decoded #122

sebastibe opened this issue Mar 12, 2017 · 8 comments

Comments

@sebastibe
Copy link

On coreapi 2.3.0 with an API running DRF 3.6.2, I'm having an error when decoding documents with enum types in the decode_schema_from_corejson function. The coreschema.Enum class which unlike the other Schema class is initializing with one enum positional argument (the list of possible values) for validation purpose. This list is not directly available in the document so I'm not sure how you would like to initialize the class in that case.

The solutions I'm seeing is either to add the enums to the document (maybe it's already the case and I missed this part) and initialize the class properly or make the enum optional as a keyword argument for now.

@tomchristie
Copy link
Contributor

Thanks, yup looks like those are currently missing from the document and need to be included.

@sebastibe
Copy link
Author

In the meantime, should we patch coreschema.Enum: 'enum' as coreschema.String: 'enum' in the corejson codec? This would make the clients works with API exposing Enums while currently I imagine everyone using 2.3.0 with DRF 3.6 and choices field must have this error.

@MattFisher
Copy link

Updated from DRF 3.5.3 to 3.6.2 but have had to roll back to 3.5.4 because of this issue (and the model_field used before defined error in 3.6.0 and 3.6.1).

@ozw1z5rd
Copy link

Hello, is there a fast solution to have DRF working without the cori-api patch?

@dkvdm
Copy link

dkvdm commented May 3, 2017

Building against #126 will temporarily solve this issue until the next release of coreapi has been released.

@tomchristie
Copy link
Contributor

Closed via #135

@kiruh
Copy link

kiruh commented Jul 24, 2017

I've met the same problem. What can I do to solve it?

Here are the versions of packages that I use:

coreapi==2.2.4
coreapi-cli==1.0.6
coreschema==0.0.4
djangorestframework==3.6.3

Here's the error I get

$ coreapi get http://127.0.0.1:8000/schema/ --debug
> GET /schema/ HTTP/1.1
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Accept: application/coreapi+json, application/vnd.coreapi+json, */*
> Authorization: Basic a2lyaWxsOnFhendzeGVkY3IxMjM=
> Host: 127.0.0.1
> User-Agent: coreapi
< 200 OK
< Allow: GET, HEAD, OPTIONS
< Content-Length: 17858
< Content-Type: application/coreapi+json
< Date: Mon, 24 Jul 2017 20:40:06 GMT
< Server: WSGIServer/0.1 Python/2.7.12
< Vary: Accept, Cookie
< X-Frame-Options: SAMEORIGIN
< 
< /* Response ... */

Traceback (most recent call last):
  File "/home/kirill/testdrf/env/bin/coreapi", line 11, in <module>
    sys.exit(client())
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi_cli/main.py", line 201, in get
    doc = client.get(url, force_codec=force_codec)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/client.py", line 131, in get
    return transport.transition(link, decoders, force_codec=force_codec)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/transports/http.py", line 332, in transition
    result = _decode_result(response, decoders, force_codec)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/transports/http.py", line 249, in _decode_result
    result = codec.load(response.content, **options)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/base.py", line 24, in load
    return self.decode(*args, **kwargs)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 306, in decode
    doc = _primative_to_document(data, base_url)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 234, in _primative_to_document
    content = _get_content(data, base_url=url)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 132, in _get_content
    for key, value in item.items()
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 133, in <dictcomp>
    if key not in ('_type', '_meta')
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 276, in _primative_to_document
    content = _get_content(data, base_url=base_url)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 132, in _get_content
    for key, value in item.items()
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 133, in <dictcomp>
    if key not in ('_type', '_meta')
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 267, in _primative_to_document
    for item in fields if isinstance(item, dict)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 58, in _get_schema
    return decode_schema_from_corejson(schema_data)
  File "/home/kirill/testdrf/env/local/lib/python2.7/site-packages/coreapi/codecs/corejson.py", line 48, in decode_schema_from_corejson
    return schema_cls(title=title, description=description)
TypeError: __init__() takes exactly 2 arguments (1 given)

I've tries it with:

coreapi==2.2.4
coreapi-cli==1.0.2
coreschema==0.0.4
djangorestframework==3.5.4

But it didn't help me at all.

@dkvdm
Copy link

dkvdm commented Jul 24, 2017

Update CoreAPI to 2.3.1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants