osohq / gitclub

Realistic examples of using Oso in an application for authorization. Built for multiple different backends.
54 stars 16 forks source link

Python errors with flask-sqlalchemy backend example #47

Open shnplr opened 1 year ago

shnplr commented 1 year ago
  1. Initial error:
(venv) > pip3 install -r requirements.txt
Collecting flask~=1.1.4 (from -r requirements.txt (line 1))
  Using cached Flask-1.1.4-py2.py3-none-any.whl (94 kB)
Collecting SQLAlchemy~=1.3.20 (from -r requirements.txt (line 2))
  Using cached SQLAlchemy-1.3.24.tar.gz (6.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
ERROR: Could not find a version that satisfies the requirement oso==0.25.1 (from versions: 0.26.4, 0.27.0)
ERROR: No matching distribution found for oso==0.25.1
  1. after installing oso 0.26.4
(venv) $ FLASK_APP="app:create_app(None, True)" flask run
Traceback (most recent call last):
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/bin/flask", line 5, in <module>
    from flask.cli import main
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/markupsafe/__init__.py)
  1. after downgrading markupsafe -> 2.0.1
(venv) > FLASK_APP="app:create_app(None, True)" flask run
 * Serving Flask app "app:create_app(None, True)"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/bin/flask", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 848, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 305, in __init__
    self._load_unlocked()
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 330, in _load_unlocked
    self._app = rv = self.loader()
                     ^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 259, in locate_app
    return find_app_by_string(script_info, module, app_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 184, in find_app_by_string
    app = call_factory(script_info, attr, args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/venv/lib/python3.11/site-packages/flask/cli.py", line 115, in call_factory
    return app_factory(*arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/app/__init__.py", line 73, in create_app
    init_oso(app, Session)
  File "/XXX/osohq/gitclub/backends/flask-sqlalchemy/app/__init__.py", line 150, in init_oso
    oso.register_class(
TypeError: Polar.register_class() got an unexpected keyword argument 'build_query'
gsarjeant commented 1 year ago

I'm not able to reproduce the missing oso 0.25.1 behavior, so it appears that that is fixed.

I can reproduce the issue with markupsafe, which also affects the flask-sqlalchemy-oso backend example. The soft_unicode method was removed in this PR, which was included in the 2.1.0 release. Jinja2 2.x still relies on it. The last compatible release of markupsafe was 2.0.1.