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

"Api object has no attribute _extract_schemas" #2

Closed
ianseyer opened this issue Feb 2, 2018 · 4 comments
Closed

"Api object has no attribute _extract_schemas" #2

ianseyer opened this issue Feb 2, 2018 · 4 comments

Comments

@ianseyer
Copy link

ianseyer commented Feb 2, 2018

Hi there!

Excited about this project, and I appreciate your work.

Attempting to run this on pre-existing sqlalchemy models, I get the following error:

api_1       | Traceback (most recent call last):
api_1       |   File "./swagger.py", line 54, in <module>
api_1       |     create_api(app)
api_1       |   File "./swagger.py", line 26, in create_api
api_1       |     api.expose_object(Market)
api_1       |   File "/usr/local/lib/python3.6/site-packages/safrs/jsonapi.py", line 112, in expose_object
api_1       |     methods = ['GET','POST', 'PUT'])
api_1       |   File "/usr/local/lib/python3.6/site-packages/safrs/jsonapi.py", line 265, in add_resource
api_1       |     operation, definitions_ = self._extract_schemas(operation)
api_1       | AttributeError: 'Api' object has no attribute '_extract_schemas'
api_1       | unable to load app 0 (mountpoint='') (callable not found or import error)
api_1       | *** no app loaded. going in full dynamic mode ***
api_1       | *** uWSGI is running in multiple interpreter mode ***
api_1       | spawned uWSGI worker 1 (and the only) (pid: 13, cores: 1)

This is running against objects that inherit from SAFRSBase.

The code is the same as the example, butwith my own models, and exposing them via expose_object.

In addition, I have tried it with the exact test code, replaced sqlite with postgres, and get the same error.

@thomaxxl
Copy link
Owner

thomaxxl commented Feb 2, 2018

Hi,

Glad you like it! I'll get this resolved asap.
For me things work fine with postgres using

examples/demo_relationship.py:23:app.config.update( SQLALCHEMY_DATABASE_URI = 'postgres://tmpuser:tmppwd@localhost/tmpdb' )

the _extract_schemas method is inherited from flask_restful_swagger_2's Api class ( "flask-restful-swagger-2==0.33" ), eg.

In [4]: from flask_restful_swagger_2 import Api;print(Api._extract_schemas)
<function Api._extract_schemas at 0x7f1f345ce2f0>

Can you share the code you have so I can reproduce it please?

@frankthetank
Copy link

Hi guys,

I am experiencing this same issue and believe I found the problem. Pip installed flask_restful_swagger-2==0.35 which does not contain a _extract_schemas method within flask_restful_swagger_2.py:Api(restful_Api). If I force pip to install flask_restful_swagger-2==0.33 and inspect that object I see that it does contain the appropriate method.

Regarding the new FRS version, it exists in _BaseExtractorImpl(Extractor) which is in the same module but definitely not in the class. I could not see where any extractor was wired in to the current object. I suppose the questions are 1) whether the FRS guys provided a migration path for this method and 2) whether your deployment script is being properly executed through tools such as pip, including evaluation of dependencies.

Regarding the last, if I run pip install safrs --target project/dependencies on a system that has no other flask modules installed then pip does not pull in any of the other dependencies. If I run pip install flask_restful_swagger_2 then it installs this module with all of its dependencies, potentially at an incompatible version.

@thomaxxl
Copy link
Owner

thomaxxl commented Feb 3, 2018

Thanks for bringing this up!

The fix turns out to be pretty simple, I can use the Extractor class from FRS :

from flask_restful_swagger_2 import validate_path_item_object, extract_swagger_path, Extractor

then do

operation, definitions_ = Extractor.extract(operation)

I committed the fix to github. I have to do some more testing and
I will make a new pip package monday, and I'll include the dependencies in the setup.py

Thanks again Frank & Ian!

@thomaxxl
Copy link
Owner

thomaxxl commented Feb 5, 2018

safrs 1.0.3

@thomaxxl thomaxxl closed this as completed Feb 5, 2018
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

3 participants