Hi Everyone,
I am working on the Travel Sites assignment in the Flask course: https://www.codecademy.com/paths/build-python-web-apps-flask/tracks/flask-advanced-functionality/modules/flask-accounts-authentication/projects/flask-accounts-authentication.
I am recreating the project in Visual Studio Code.
In step 20 I am trying to complete a registration form, however when I actually tested it and created a user I got:
[2022-09-04 20:35:34,949] ERROR in app: Exception on /register [POST]
Traceback (most recent call last):
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/clsregistry.py”, line 393, in _resolve_name
rval = d[token]
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/util/_collections.py”, line 746, in missing
self[key] = val = self.creator(key)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/clsregistry.py”, line 372, in _access_cls
return self.fallback[key]
KeyError: ‘Post’
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/flask/app.py”, line 2525, in wsgi_app
response = self.full_dispatch_request()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/flask/app.py”, line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/flask/app.py”, line 1820, in full_dispatch_request
rv = self.dispatch_request()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/flask/app.py”, line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/routes.py”, line 23, in register
user = User(username=form.username.data, email=form.email.data)
File “”, line 4, in init
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/state.py”, line 476, in _initialize_instance
manager.dispatch.init(self, args, kwargs)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/event/attr.py”, line 343, in call
fn(*args, **kw)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py”, line 3633, in _event_on_init
instrumenting_mapper._check_configure()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py”, line 1924, in _check_configure
_configure_registries({self.registry}, cascade=True)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py”, line 3448, in _configure_registries
_do_configure_registries(registries, cascade)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py”, line 3487, in _do_configure_registries
mapper._post_configure_properties()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py”, line 1941, in _post_configure_properties
prop.init()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/interfaces.py”, line 231, in init
self.do_init()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/relationships.py”, line 2145, in do_init
self._process_dependent_arguments()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/relationships.py”, line 2240, in _process_dependent_arguments
self.target = self.entity.persist_selectable
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py”, line 1113, in get
obj.dict[self.name] = result = self.fget(obj)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/relationships.py”, line 2107, in entity
argument = self._clsregistry_resolve_name(self.argument)()
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/clsregistry.py”, line 397, in _resolve_name
self.raise_for_name(name, err)
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/orm/clsregistry.py”, line 375, in raise_for_name
util.raise(
File “/Users/maksymlysikov/Study/Python/travelapp/.venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py”, line 208, in raise
raise exception
sqlalchemy.exc.InvalidRequestError: When initializing mapper mapped class User->user, expression ‘Post’ failed to locate a name (‘Post’). If this is a class name, consider adding this relationship() to the <class ‘models.User’> class after both dependent classes have been defined.
127.0.0.1 - - [04/Sep/2022 20:35:34] “POST /register HTTP/1.1” 500 -
My models.py file:
Can someone help with the root cause of the issue and how to fix it?
I also published the project on my GitHub: https://github.com/maxlys/travelapp