sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column users.role does not exist LINE 1: ...ar AS users_avatar, users.status AS users_status, users.role... ^ [SQL: SELECT users.id AS users_id, users.username AS users_username, users.email AS users_email, users.phone AS users_phone, users.password AS users_password, users.fullname AS users_fullname, users.avatar AS users_avatar, users.status AS users_status, users.role AS users_role, users.locate AS users_locate, users.timezone AS users_timezone, users.created_at AS users_created_at, users.updated_at AS users_updated_at FROM users WHERE users.username IS NULL LIMIT %(param_1)s] [parameters: {'param_1': 1}] (Background on this error at: https://sqlalche.me/e/20/f405)
_exec_single_context
context,
):
evt_handled = True
break
if not evt_handled:
self.dialect.do_execute(
cursor, str_statement, effective_parameters, context
)
if self._has_events or self.engine._has_events:
self.dispatch.after_cursor_execute(
do_execute
def do_executemany(self, cursor, statement, parameters, context=None):
cursor.executemany(statement, parameters)
def do_execute(self, cursor, statement, parameters, context=None):
cursor.execute(statement, parameters)
def do_execute_no_params(self, cursor, statement, context=None):
cursor.execute(statement)
def is_disconnect(self, e, connection, cursor):
__call__
def __call__(self, environ: dict, start_response: t.Callable) -> t.Any:
"""The WSGI server calls the Flask application object as the
WSGI application. This calls :meth:`wsgi_app`, which can be
wrapped to apply middleware.
"""
return self.wsgi_app(environ, start_response)
wsgi_app
try:
ctx.push()
response = self.full_dispatch_request()
except Exception as e:
error = e
response = self.handle_exception(e)
except: # noqa: B001
error = sys.exc_info()[1]
raise
return response(environ, start_response)
finally:
wsgi_app
ctx = self.request_context(environ)
error: BaseException | None = None
try:
try:
ctx.push()
response = self.full_dispatch_request()
except Exception as e:
error = e
response = self.handle_exception(e)
except: # noqa: B001
error = sys.exc_info()[1]
full_dispatch_request
request_started.send(self, _async_wrapper=self.ensure_sync)
rv = self.preprocess_request()
if rv is None:
rv = self.dispatch_request()
except Exception as e:
rv = self.handle_user_exception(e)
return self.finalize_request(rv)
def finalize_request(
self,
rv: ft.ResponseReturnValue | HTTPException,
full_dispatch_request
try:
request_started.send(self, _async_wrapper=self.ensure_sync)
rv = self.preprocess_request()
if rv is None:
rv = self.dispatch_request()
except Exception as e:
rv = self.handle_user_exception(e)
return self.finalize_request(rv)
def finalize_request(
dispatch_request
and req.method == "OPTIONS"
):
return self.make_default_options_response()
# otherwise dispatch to the handler for that endpoint
view_args: dict[str, t.Any] = req.view_args # type: ignore[assignment]
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
def full_dispatch_request(self) -> Response:
"""Dispatches the request and on top of that performs request
pre and postprocessing as well as HTTP exception catching and
error handling.
register
if result['status'] == 200:
return redirect(url_for('default.login'))
else:
return render_template(temp + 'register.html', data=data, error=result['message'])
return render_template(temp + 'register.html', data=data)
@bp.route('/logout')
@login_required
def logout():
render_template
a list is given, the first name to exist will be rendered.
:param context: The variables to make available in the template.
"""
app = current_app._get_current_object() # type: ignore[attr-defined]
template = app.jinja_env.get_or_select_template(template_name_or_list)
return _render(app, template, context)
def render_template_string(source: str, **context: t.Any) -> str:
"""Render a template from the given source string with the given
context.
_render
return list(result)
def _render(app: Flask, template: Template, context: dict[str, t.Any]) -> str:
app.update_template_context(context)
before_render_template.send(
app, _async_wrapper=app.ensure_sync, template=template, context=context
)
rv = template.render(context)
template_rendered.send(
update_template_context
orig_ctx = context.copy()
for name in names:
if name in self.template_context_processors:
for func in self.template_context_processors[name]:
context.update(func())
context.update(orig_ctx)
def make_shell_context(self) -> dict:
"""Returns the shell context for an interactive shell for this
_user_context_processor
h.update(base.encode("utf8"))
return h.hexdigest()
def _user_context_processor():
return dict(current_user=_get_user())
def _secret_key(key=None):
if key is None:
key = current_app.config["SECRET_KEY"]
_get_user
def _get_user():
if has_request_context():
if "_login_user" not in g:
current_app.login_manager._load_user()
return g._login_user
return None
_load_user
)
if has_cookie:
cookie = request.cookies[cookie_name]
user = self._load_user_from_remember_cookie(cookie)
elif self._request_callback:
user = self._load_user_from_request(request)
elif header_name in request.headers:
header = request.headers[header_name]
user = self._load_user_from_header(header)
return self._update_request_context_with_user(user)
_load_user_from_request
return user
return None
def _load_user_from_request(self, request):
if self._request_callback:
user = self._request_callback(request)
if user is not None:
app = current_app._get_current_object()
user_loaded_from_request.send(app, user=user)
return user
return None
request_loader
@login_manager.request_loader
def request_loader(request):
username = request.form.get('username')
user = Users.query.filter_by(username=username).first()
return user if user else None
# class OAuth(OAuthConsumerMixin, db.Model):
# user_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="cascade"), nullable=False)
first
"""
# replicates limit(1) behavior
if self._statement is not None:
return self._iter().first() # type: ignore
else:
return self.limit(1)._iter().first() # type: ignore
def one_or_none(self) -> Optional[_T]:
"""Return at most one result or raise an exception.
Returns ``None`` if the query selects
_iter
def _iter(self) -> Union[ScalarResult[_T], Result[_T]]:
# new style execution.
params = self._params
statement = self._statement_20()
result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
statement,
params,
execution_options={"_sa_orm_load_options": self.load_options},
)
execute
:return: a :class:`_engine.Result` object.
"""
return self._execute_internal(
statement,
params,
execution_options=execution_options,
bind_arguments=bind_arguments,
_parent_execute_state=_parent_execute_state,
_execute_internal
return conn.scalar(
statement, params or {}, execution_options=execution_options
)
if compile_state_cls:
result: Result[Any] = compile_state_cls.orm_execute_statement(
self,
statement,
params or {},
execution_options,
bind_arguments,
orm_execute_statement
params,
execution_options,
bind_arguments,
conn,
) -> Result:
result = conn.execute(
statement, params or {}, execution_options=execution_options
)
return cls.orm_setup_cursor_result(
session,
statement,
execute
try:
meth = statement._execute_on_connection
except AttributeError as err:
raise exc.ObjectNotExecutableError(statement) from err
else:
return meth(
self,
distilled_parameters,
execution_options or NO_OPTIONS,
)
_execute_on_connection
execution_options: CoreExecuteOptionsParameter,
) -> Result[Any]:
if self.supports_execution:
if TYPE_CHECKING:
assert isinstance(self, Executable)
return connection._execute_clauseelement(
self, distilled_params, execution_options
)
else:
raise exc.ObjectNotExecutableError(self)
_execute_clauseelement
column_keys=keys,
for_executemany=for_executemany,
schema_translate_map=schema_translate_map,
linting=self.dialect.compiler_linting | compiler.WARN_LINTING,
)
ret = self._execute_context(
dialect,
dialect.execution_ctx_cls._init_compiled,
compiled_sql,
distilled_parameters,
execution_options,
_execute_context
return self._exec_insertmany_context(
dialect,
context,
)
else:
return self._exec_single_context(
dialect, context, statement, parameters
)
def _exec_single_context(
self,
_exec_single_context
context.post_exec()
result = context._setup_result_proxy()
except BaseException as e:
self._handle_dbapi_exception(
e, str_statement, effective_parameters, cursor, context
)
return result
_handle_dbapi_exception
if newraise:
raise newraise.with_traceback(exc_info[2]) from e
elif should_wrap:
assert sqlalchemy_exception is not None
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
else:
assert exc_info[1] is not None
raise exc_info[1].with_traceback(exc_info[2])
finally:
del self._reentrant_error
_exec_single_context
context,
):
evt_handled = True
break
if not evt_handled:
self.dialect.do_execute(
cursor, str_statement, effective_parameters, context
)
if self._has_events or self.engine._has_events:
self.dispatch.after_cursor_execute(
do_execute
def do_executemany(self, cursor, statement, parameters, context=None):
cursor.executemany(statement, parameters)
def do_execute(self, cursor, statement, parameters, context=None):
cursor.execute(statement, parameters)
def do_execute_no_params(self, cursor, statement, context=None):
cursor.execute(statement)
def is_disconnect(self, e, connection, cursor):
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column users.role does not exist LINE 1: ...ar AS users_avatar, users.status AS users_status, users.role... ^ [SQL: SELECT users.id AS users_id, users.username AS users_username, users.email AS users_email, users.phone AS users_phone, users.password AS users_password, users.fullname AS users_fullname, users.avatar AS users_avatar, users.status AS users_status, users.role AS users_role, users.locate AS users_locate, users.timezone AS users_timezone, users.created_at AS users_created_at, users.updated_at AS users_updated_at FROM users WHERE users.username IS NULL LIMIT %(param_1)s] [parameters: {'param_1': 1}] (Background on this error at: https://sqlalche.me/e/20/f405)
This is the Copy/Paste friendly version of the traceback.
The console is locked and needs to be unlocked by entering the PIN. You can find the PIN printed out on the standard output of your shell that runs the server.