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

sqlalchemy.exc.StatementError when adding new sketch from ui #886

Closed
garanews opened this issue May 7, 2019 · 5 comments
Closed

sqlalchemy.exc.StatementError when adding new sketch from ui #886

garanews opened this issue May 7, 2019 · 5 comments
Assignees
Labels

Comments

@garanews
Copy link
Contributor

garanews commented May 7, 2019

I'm getting
`
sqlalchemy.exc.StatementError

sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) Can't resolve value for column sketch.id on object <Sketch at 0x7f675e9aeb38>; no value has been set for this column
[SQL: SELECT sketch_accesscontrolentry.id AS sketch_accesscontrolentry_id, sketch_accesscontrolentry.created_at AS sketch_accesscontrolentry_created_at, sketch_accesscontrolentry.updated_at AS sketch_accesscontrolentry_updated_at, sketch_accesscontrolentry.permission AS sketch_accesscontrolentry_permission, sketch_accesscontrolentry.parent_id AS sketch_accesscontrolentry_parent_id, sketch_accesscontrolentry.user_id AS sketch_accesscontrolentry_user_id, sketch_accesscontrolentry.group_id AS sketch_accesscontrolentry_group_id
FROM sketch_accesscontrolentry
WHERE %(param_1)s = sketch_accesscontrolentry.user_id AND sketch_accesscontrolentry.group_id IS NULL AND sketch_accesscontrolentry.permission = %(permission_1)s AND %(param_2)s = sketch_accesscontrolentry.parent_id]
[parameters: [{}]]
`

when try to add new sketch.
I already dropped postgresql DB and recreated withtout success.
Everything was working until I deleted last sketch from ui.
I tried to install again from git (keeping current config file) with both python2 and pyton3 but same error.

Any help?

@garanews
Copy link
Contributor Author

garanews commented May 8, 2019

I tried to modify /usr/local/lib/python3.6/dist-packages/timesketch-20190207-py3.6.egg/timesketch/models/acl.py in this way:

        ace = self.AccessControlEntry.query.filter_by(
            user=user,
            group=None,
            permission=permission,
            #parent=self
            ).all()

Now I am able to create the sketch but only the first one created is shown in gui (the others are accessible specifying the direct url in path, like ..../sketch/7/)
Creating a new user the behavior is the same, only the first sketch created is shown.
I am sure the parent=self is needed, but leaving it causes the error posted before.

Any suggestion?

@lprat
Copy link
Contributor

lprat commented May 10, 2019

Hi,
The origin of problem is sqlalchemy==1.3.2, i removed and intalled sqlalchemy==1.2.8 and work! I tried with verrsion 1.3.3, but same error.
Tempory solution: pip install sqlalchemy==1.2.18

Maybe the last update of sqlalchemy/lib/sqlalchemy/orm/relationships.py:
Use "parent object" instead of "primary object"

timesketch_1 | /usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/sqltypes.py:268: SAWarning: Unicode type received non-unicode bind param value 'read'. (this warning may be suppressed after 10 occurrences)
timesketch_1 | (util.ellipses_string(value),),
timesketch_1 | [2019-05-10 11:40:21,806] ERROR in app: Exception on /sketch/ [POST]
timesketch_1 | Traceback (most recent call last):
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2292, in wsgi_app
timesketch_1 | response = self.full_dispatch_request()
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1815, in full_dispatch_request
timesketch_1 | rv = self.handle_user_exception(e)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask_restful/init.py", line 273, in error_router
timesketch_1 | return original_handler(e)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1718, in handle_user_exception
timesketch_1 | reraise(exc_type, exc_value, tb)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1813, in full_dispatch_request
timesketch_1 | rv = self.dispatch_request()
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1799, in dispatch_request
timesketch_1 | return self.view_functionsrule.endpoint
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/flask_login/utils.py", line 228, in decorated_view
timesketch_1 | return func(*args, **kwargs)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/timesketch/views/home.py", line 59, in home
timesketch_1 | sketch.grant_permission(permission='read', user=current_user)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/timesketch/models/acl.py", line 248, in grant_permission
timesketch_1 | if not self._get_ace(permission, user=user, check_group=False):
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/timesketch/models/acl.py", line 162, in _get_ace
timesketch_1 | user=user, group=None, permission=permission, parent=self).all()
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3161, in all
timesketch_1 | return list(self)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3317, in iter
timesketch_1 | return self._execute_and_instances(context)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3342, in _execute_and_instances
timesketch_1 | result = conn.execute(querycontext.statement, self._params)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 988, in execute
timesketch_1 | return meth(self, multiparams, params)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection
timesketch_1 | return connection._execute_clauseelement(self, multiparams, params)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1107, in _execute_clauseelement
timesketch_1 | distilled_params,
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
timesketch_1 | e, util.text_type(statement), parameters, None, None
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1466, in _handle_dbapi_exception
timesketch_1 | util.raise_from_cause(sqlalchemy_exception, exc_info)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 383, in raise_from_cause
timesketch_1 | reraise(type(exception), exception, tb=exc_tb, cause=cause)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1179, in _execute_context
timesketch_1 | context = constructor(dialect, self, conn, *args)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 683, in _init_compiled
timesketch_1 | for grp, m in enumerate(parameters)
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/compiler.py", line 692, in construct_params
timesketch_1 | pd[self.bind_names[bindparam]] = bindparam.effective_value
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 1213, in effective_value
timesketch_1 | return self.callable()
timesketch_1 | File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/relationships.py", line 1587, in _go
timesketch_1 | % (column, state_str(state))
timesketch_1 | StatementError: (sqlalchemy.exc.InvalidRequestError) Can't resolve value for column sketch.id on object <Sketch at 0x7f1643317890>; no value has been set for this column
timesketch_1 | [SQL: SELECT sketch_accesscontrolentry.id AS sketch_accesscontrolentry_id, sketch_accesscontrolentry.created_at AS sketch_accesscontrolentry_created_at, sketch_accesscontrolentry.updated_at AS sketch_accesscontrolentry_updated_at, sketch_accesscontrolentry.permission AS sketch_accesscontrolentry_permission, sketch_accesscontrolentry.parent_id AS sketch_accesscontrolentry_parent_id, sketch_accesscontrolentry.user_id AS sketch_accesscontrolentry_user_id, sketch_accesscontrolentry.group_id AS sketch_accesscontrolentry_group_id
timesketch_1 | FROM sketch_accesscontrolentry
timesketch_1 | WHERE sketch_accesscontrolentry.group_id IS NULL AND %(param_1)s = sketch_accesscontrolentry.user_id AND %(param_2)s = sketch_accesscontrolentry.parent_id AND sketch_accesscontrolentry.permission = %(permission_1)s]
timesketch_1 | [parameters: [{}]]

@garanews
Copy link
Contributor Author

I was using sqlalchemy==1.3.3
Downgrading to 1.2.18 seems resolve the issue.
Big Thanks!

@berggren
Copy link
Contributor

This is now fixed (#897) - We were setting the ACL before the index was committed to the DB. This broke in recent SQLAlchemy updates.

@qris
Copy link

qris commented Dec 4, 2019

If you end up here searching for this error message, it's likely that you're querying a relationship for objects that have not yet been added to a session, so they have no primary key. This is newly an error in SQLAlchemy 1.3; previously it would just return no results. See abrt/faf#764 (comment) for details.

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

4 participants