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

Incorrectly parsed reference fails to resolve #395

Closed
bartfeenstra opened this issue Dec 17, 2017 · 15 comments
Closed

Incorrectly parsed reference fails to resolve #395

bartfeenstra opened this issue Dec 17, 2017 · 15 comments

Comments

@bartfeenstra
Copy link

bartfeenstra commented Dec 17, 2017

I'm using the latest stable CDN-hosted ReDoc version on the Swagger 2.0 and JSON Schema documents at the end of this post. When loading this in ReDoc, it fails with the following error: ERROR Error: Uncaught (in promise): SyntaxError: Error resolving $ref pointer "http://127.0.0.1:5000/about/json/schema#/definitions/schema". Token "schema" does not exist.. As you can see in the documents below, this subschema does indeed not exist, but I don't know why ReDoc tries to load it. I'm hoping someone here might. The same JSON schema is also parsed and resolved by a Python library, which works well, so at this point like the error is caused by something on ReDoc's side.

Please let me know if I can provide more information. Once #388 has been addressed, I can hopefully help debug this error myself locally :)

Swagger spec:

{
   "swagger":"2.0",
   "info":{
      "title":"Alfred",
      "version":"0.0.0",
      "description":"This document describes Alfred's HTTP API in the [OpenApi 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) format."
   },
   "definitions":{

   },
   "parameters":{

   },
   "paths":{
      "/about/json/schema":{
         "get":{
            "operationId":"schema",
            "consumes":[

            ],
            "produces":[
               "application/schema+json"
            ],
            "responses":{
               "200":{
                  "description":"A successful response.",
                  "schema":{
                     "$ref":"http://127.0.0.1:5000/about/json/schema#/definitions/response/schema"
                  }
               },
               "406":{
                  "$ref":"#/responses/406"
               },
               "415":{
                  "$ref":"#/responses/415"
               }
            }
         }
      },
      "/about/json/external-schema/{id}":{
         "get":{
            "operationId":"external-schema",
            "consumes":[

            ],
            "produces":[
               "application/schema+json"
            ],
            "responses":{
               "200":{
                  "description":"A successful response.",
                  "schema":{
                     "$ref":"http://127.0.0.1:5000/about/json/schema#/definitions/response/schema"
                  }
               },
               "406":{
                  "$ref":"#/responses/406"
               },
               "415":{
                  "$ref":"#/responses/415"
               }
            }
         }
      },
      "/about/openapi":{
         "get":{
            "operationId":"openapi",
            "consumes":[

            ],
            "produces":[
               "application/json",
               "text/html"
            ],
            "responses":{
               "200":{
                  "description":"A successful response.",
                  "schema":{
                     "$ref":"http://127.0.0.1:5000/about/json/schema#/definitions/response/openapi"
                  }
               },
               "406":{
                  "$ref":"#/responses/406"
               },
               "415":{
                  "$ref":"#/responses/415"
               }
            }
         }
      }
   },
   "tags":[

   ],
   "responses":{
      "406":{
         "description":"Returned if the request `Accept` header does not contain any content type produced by this endpoint."
      },
      "415":{
         "description":"Returned if the request `Content-Type` header does not contain any content type consumed by this endpoint."
      }
   },
   "host":"127.0.0.1:5000",
   "schemes":[
      "http"
   ]
}

JSON Schema:

{
   "id":"http://127.0.0.1:5000/about/json/schema",
   "$schema":"http://json-schema.org/draft-04/schema#",
   "enum":[
      null
   ],
   "definitions":{
      "request":{

      },
      "response":{
         "schema":{
            "anyOf":[
               {
                  "$ref":"http://127.0.0.1:5000/about/json/schema#/definitions/response/error"
               },
               {
                  "$ref":"http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL2pzb24tc2NoZW1hLm9yZy9kcmFmdC0wNC9zY2hlbWE%3D",
                  "description":"A JSON Schema."
               }
            ]
         },
         "openapi":{
            "$ref":"http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL3N3YWdnZXIuaW8vdjIvc2NoZW1hLmpzb24%3D",
            "description":"An OpenAPI/Swagger 2.0 schema."
         },
         "error":{
            "title":"Error response",
            "type":"object",
            "properties":{
               "errors":{
                  "type":"array",
                  "items":{
                     "$ref":"http://127.0.0.1:5000/about/json/schema#/definitions/data/error"
                  }
               }
            },
            "required":[
               "errors"
            ]
         }
      },
      "data":{
         "error":{
            "title":"An API error",
            "type":"object",
            "properties":{
               "code":{
                  "title":"The machine-readable error code.",
                  "type":"string"
               },
               "title":{
                  "title":"The human-readable error title.",
                  "type":"string"
               }
            },
            "required":[
               "code",
               "title"
            ]
         }
      }
   }
}
@RomanHotsiy
Copy link
Member

Hey @bartfeenstra 🙌 !
Sorry for the late reply for this. Finally, I've found some time to dig into this.
I tried to simplify this schema a bit and it works just fine for me...
I suspect that the issue is caused by contents of http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL2pzb24tc2NoZW1hLm9yZy9kcmFmdC0wNC9zY2hlbWE%3D or http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL3N3YWdnZXIuaW8vdjIvc2NoZW1hLmpzb24%3D
Could you share this?

@bartfeenstra
Copy link
Author

bartfeenstra commented Jan 22, 2018

Hi Roman!

Those URLs are proxies for external/third-party JSON schemas. You can base64-decode the last URL path component to see the real schema ID being requested.

Or, to reproduce this locally, run the following command in a terminal: git clone https://github.com/bartfeenstra/alfred.git alfred && cd alfred && python3 -m virtualenv -p `which python3` venv && . ./venv/bin/activate && pip install -r requirements-dev-frozen.txt && ./bin/run alfred_openapi.extension.OpenApiExtension
You must replace the two python3 occurrences in that command with the name of the Python (3.5+) executable you wish to use for this installation.

This command will not exit, but will idle after starting a web server and wait for you to quit the command. Before quitting, go to http://127.0.0.1:5000/about/openapi to see ReDoc in action. I guess the easiest way to inspect exactly what HTTP responses ReDoc gets back, is to monitor the web page's network traffic through your browser's debugging/inspection tool when visiting the ReDoc page.

Once you are done and want to get rid of the application, you can remove the entire cloned Git repo. All of my application's dependencies will be installed locally, and no trace will remain. If you had to install a specific Python version or Virtualenv yourself, those will remain on your system, but they are generic Python tools and not specific to anything in this issue. You may remove those through the same package manager you used to install them, if you'd like.

Please let me know if there is any other information I can provide :)

Thanks!

@bartfeenstra
Copy link
Author

Note that the branch I originally documented in my previous comment was merged into master. I updated the instructions accordingly.

@bartfeenstra
Copy link
Author

Now it no longer errors out as it did originally, but it just seems to get stuck in a loop, resulting in my laptop sounding like it's trying to take off on its fan alone 😁

@bartfeenstra
Copy link
Author

bartfeenstra commented Feb 2, 2018

I managed to run ReDoc locally using its dev server, allowing me to debug the code through my browser (I learned a thing!). As it turns out, SchemaWalker ends up in an infinite loop when parsing the official JSON core schema (as proxied through my app).
Stack trace:

Error: Script terminated by timeout at:
parse@http://localhost:9000/redoc.js:48472:12
JsonPointer.parse@http://localhost:9000/redoc.js:17765:16
JsonPointer.join@http://localhost:9000/redoc.js:17776:26
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31835:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27
SchemaWalker.walkEach@http://localhost:9000/redoc.js:31836:23
SchemaWalker.walk@http://localhost:9000/redoc.js:31802:13
SchemaWalker.walk@http://localhost:9000/redoc.js:31810:27

I logged the pointers as the schema walker traversed the data:

/paths/~1about~1json~1schema/get/responses/200/schema/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/properties/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/patternProperties/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/dependencies/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/properties/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/patternProperties/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/dependencies/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties
schema-normalizer.service.ts:64:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties
schema-normalizer.service.ts:58:6
/paths/~1about~1json~1schema/get/responses/200/schema/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties/properties/definitions/additionalProperties

where /paths/~1about~1json~1schema/get/responses/200/schema is a reference to the core JSON Schema schema as proxied through my app:

{
   "id":"http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL2pzb24tc2NoZW1hLm9yZy9kcmFmdC0wNC9zY2hlbWE%3D",
   "$schema":"http://127.0.0.1:5000/about/json/external-schema/aHR0cDovL2pzb24tc2NoZW1hLm9yZy9kcmFmdC0wNC9zY2hlbWE%3D",
   "description":"Core schema meta-schema",
   "definitions":{
      "schemaArray":{
         "type":"array",
         "minItems":1,
         "items":{
            "$ref":"#"
         }
      },
      "positiveInteger":{
         "type":"integer",
         "minimum":0
      },
      "positiveIntegerDefault0":{
         "allOf":[
            {
               "$ref":"#/definitions/positiveInteger"
            },
            {
               "default":0
            }
         ]
      },
      "simpleTypes":{
         "enum":[
            "array",
            "boolean",
            "integer",
            "null",
            "number",
            "object",
            "string"
         ]
      },
      "stringArray":{
         "type":"array",
         "items":{
            "type":"string"
         },
         "minItems":1,
         "uniqueItems":true
      }
   },
   "type":"object",
   "properties":{
      "id":{
         "type":"string",
         "format":"uri"
      },
      "$schema":{
         "type":"string",
         "format":"uri"
      },
      "title":{
         "type":"string"
      },
      "description":{
         "type":"string"
      },
      "default":{

      },
      "multipleOf":{
         "type":"number",
         "minimum":0,
         "exclusiveMinimum":true
      },
      "maximum":{
         "type":"number"
      },
      "exclusiveMaximum":{
         "type":"boolean",
         "default":false
      },
      "minimum":{
         "type":"number"
      },
      "exclusiveMinimum":{
         "type":"boolean",
         "default":false
      },
      "maxLength":{
         "$ref":"#/definitions/positiveInteger"
      },
      "minLength":{
         "$ref":"#/definitions/positiveIntegerDefault0"
      },
      "pattern":{
         "type":"string",
         "format":"regex"
      },
      "additionalItems":{
         "anyOf":[
            {
               "type":"boolean"
            },
            {
               "$ref":"#"
            }
         ],
         "default":{

         }
      },
      "items":{
         "anyOf":[
            {
               "$ref":"#"
            },
            {
               "$ref":"#/definitions/schemaArray"
            }
         ],
         "default":{

         }
      },
      "maxItems":{
         "$ref":"#/definitions/positiveInteger"
      },
      "minItems":{
         "$ref":"#/definitions/positiveIntegerDefault0"
      },
      "uniqueItems":{
         "type":"boolean",
         "default":false
      },
      "maxProperties":{
         "$ref":"#/definitions/positiveInteger"
      },
      "minProperties":{
         "$ref":"#/definitions/positiveIntegerDefault0"
      },
      "required":{
         "$ref":"#/definitions/stringArray"
      },
      "additionalProperties":{
         "anyOf":[
            {
               "type":"boolean"
            },
            {
               "$ref":"#"
            }
         ],
         "default":{

         }
      },
      "definitions":{
         "type":"object",
         "additionalProperties":{
            "$ref":"#"
         },
         "default":{

         }
      },
      "properties":{
         "type":"object",
         "additionalProperties":{
            "$ref":"#"
         },
         "default":{

         }
      },
      "patternProperties":{
         "type":"object",
         "additionalProperties":{
            "$ref":"#"
         },
         "default":{

         }
      },
      "dependencies":{
         "type":"object",
         "additionalProperties":{
            "anyOf":[
               {
                  "$ref":"#"
               },
               {
                  "$ref":"#/definitions/stringArray"
               }
            ]
         }
      },
      "enum":{
         "type":"array",
         "minItems":1,
         "uniqueItems":true
      },
      "type":{
         "anyOf":[
            {
               "$ref":"#/definitions/simpleTypes"
            },
            {
               "type":"array",
               "items":{
                  "$ref":"#/definitions/simpleTypes"
               },
               "minItems":1,
               "uniqueItems":true
            }
         ]
      },
      "allOf":{
         "$ref":"#/definitions/schemaArray"
      },
      "anyOf":{
         "$ref":"#/definitions/schemaArray"
      },
      "oneOf":{
         "$ref":"#/definitions/schemaArray"
      },
      "not":{
         "$ref":"#"
      }
   },
   "dependencies":{
      "exclusiveMaximum":[
         "maximum"
      ],
      "exclusiveMinimum":[
         "minimum"
      ]
   },
   "default":{

   }
}

To reproduce this, you can run my app locally using the instructions in #395 (comment). The Swagger spec will be available at http://127.0.0.1:5000/about/openapi.

UPDATE: I disabled proxying of the core JSON Schema schema, so my Swagger spec and JSON schema have $refs to json-schema.org instead of my own app, and the problem persists using the same stack and pointer traces.

@bartfeenstra
Copy link
Author

I tried 2.0.0-alpha11 as well, but yarn/npm start throws errors.

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Feb 21, 2018

@bartfeenstra I'm terribly sorry for the huuge delay with this 🙈 . I will look into this today!

@RomanHotsiy
Copy link
Member

@bartfeenstra I am unable to start your server using details you provided :(

First there is no ./bin/run-dev shell script. I tried using ./bin/run instead. It starts but seems that python server is not started. Getting the following error:

mounting alfred_http.flask.entry_point:app on /
Traceback (most recent call last):
  File "./alfred_http/__init__.py", line 4, in <module>
    from contracts import contract

(detailed stack trace below)

I tried running pip install contracts and pip3 install contracts but it says:

(venv) bash-3.2$ pip install contractsRequirement already satisfied: contracts in ./venv/lib/python3.5/site-packages
Requirement already satisfied: setuptools in ./venv/lib/python3.5/site-packages (from contracts)

I'm not python expert so I need your help to figure it out!

Detailed stack trace:

(venv) bash-3.2$ ./bin/run alfred_openapi.extension.OpenApiExtension
Starting web server...
Ending background processes...
*** Starting uWSGI 2.0.15 (64bit) on [Wed Feb 21 17:01:32 2018] ***
compiled with version: 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) on 21 February 2018 16:56:41
os: Darwin-17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64
nodename: MacBook-Pro.local
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /Users/romanhotsiy/Projects/play/alfred
detected binary path: /Users/romanhotsiy/Projects/play/alfred/venv/bin/uwsgi
your processes number limit is 1418
your memory page size is 4096 bytes
detected max file descriptor number: 10496
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 6
Python version: 3.5.2 (default, Oct 24 2016, 01:51:25)  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7fc805402760
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363760 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
mounting alfred_http.flask.entry_point:app on /
Traceback (most recent call last):
  File "./alfred_http/__init__.py", line 4, in <module>
    from contracts import contract
ImportError: No module named 'contracts'
unable to load app 0 (mountpoint='/') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***

@bartfeenstra
Copy link
Author

bartfeenstra commented Feb 21, 2018

My bad! The up-to-date command is indeed git clone https://github.com/bartfeenstra/alfred.git alfred && cd alfred && python3 -m virtualenv -p `which python3` venv && . ./venv/bin/activate && pip install -r requirements-dev-frozen.txt && ./bin/run alfred_openapi.extension.OpenApiExtension.

I think after you replaced run-dev with run, the command did not work because it failed the first time and because it wasn't really made to be idempotent. Could you try removing the previously created directory, and try the (correct) command again?

@bartfeenstra
Copy link
Author

@RomanGotsiy What's most tricky is what is called the Virtual Environment this command sets up (they ensure the Python dependencies aren't installed globally by default). If you ctrl+C the set-up command (because after installation it runs a web server in the foreground until you interrupt it), you'll likely see your shell prompt contain (venv). In that case, run deactivate to stop the Virtual Environment the set-up script created.

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Feb 21, 2018

OK, I am now able to run the server and to load openapi spec.
But the following URL: http://127.0.0.1:5000/about/json/schema returns 500 Server Error. Here is stacktrace from console:

Stack Trace

[2018-02-21 18:46:51,632] ERROR in app: Exception on /about/json/schema [GET]
Traceback (most recent call last):
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask_cors/extension.py", line161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, inreraise
    raise value
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/views.py", line 149, in dispatch_request
    return meth(*args, **kwargs)
  File "./alfred_http/flask/app.py", line 158, in _view
    alfred_response, content_type)
  File "", line 2, in to_http_response
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_http/endpoints.py", line 329, in to_http_response
    response.payload, content_type)
  File "", line 2, in _to_http_response_payload
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_http/endpoints.py", line 339, in _to_http_response_payload
    content_type)
  File "", line 2, in to_http_response_body
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_rest/endpoints.py", line 67, in to_http_response_body
    json_data = self._data_type.to_json(payload)
  File "./alfred_rest/endpoints.py", line 145, in to_json
    data = rewriter.rewrite(data)
  File "", line 2, in rewrite
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_json/rewriter.py", line 86, in rewrite
    schema = rewriter.rewrite(schema)
  File "", line 2, in rewrite
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_json/rewriter.py", line 47, in rewrite
    schema, definitions = self._rewrite(schema, {})
  File "", line 2, in _rewrite
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 262, in contracts_checker
    result = function_(*args, **kwargs)
  File "./alfred_json/rewriter.py", line 70, in _rewrite
    data[key], definitions = self._rewrite(item, definitions)
  File "", line 2, in _rewrite
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/main.py", line 266, in contracts_checker
    returns_parsed._check_contract(context, result, silent=False)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/interface.py", line 439, in _check_contract
    self.check_contract(context, value, silent)
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/contracts/library/types_misc.py", line 20, in check_contract
    if not isinstance(value, self.types):
  File "/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/typing.py", line 725, in __instancecheck__
    raise TypeError("Tuples cannot be used with isinstance().")
TypeError: Tuples cannot be used with isinstance().
[pid: 67366|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 638 bytes} [Wed Feb 21 18:46:51 2018] GET /about/json/schema => generated 291 bytes in 22 msecs (HTTP/1.1 500) 3 headers in 116 bytes (2 switches on core 0)

@bartfeenstra
Copy link
Author

I think this is a Python 3.5 issue, but I don't see any of my tests (run on 3.5 and 3.6) failing. I'll try to reproduce and fix this. In the meantime, would you have a local Python 3.6 installation locally? If so, use the same command, but make sure the two python3 references instead point to the Python 3.6 binary.

@bartfeenstra
Copy link
Author

I removed this particular piece of code (a type check that wasn't supported until Python 3.6, I believe) on master, so you should be able to remove the folder and re-try the command.

@RomanHotsiy
Copy link
Member

@bartfeenstra should be fixed in the latest release v1.21.1

@bartfeenstra
Copy link
Author

Awesome, it works like a charm now. Thank you very much!

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

No branches or pull requests

2 participants