{"action":"created","issue":{"url":"https://api.github.com/repos/websauna/websauna/issues/146","repository_url":"https://api.github.com/repos/websauna/websauna","labels_url":"https://api.github.com/repos/websauna/websauna/issues/146/labels{/name}","comments_url":"https://api.github.com/repos/websauna/websauna/issues/146/comments","events_url":"https://api.github.com/repos/websauna/websauna/issues/146/events","html_url":"https://github.com/websauna/websauna/issues/146","id":273828781,"number":146,"title":"Override websauna.system.user.models.User question","user":{"login":"Fazik","id":13086726,"avatar_url":"https://avatars0.githubusercontent.com/u/13086726?v=4","gravatar_id":"","url":"https://api.github.com/users/Fazik","html_url":"https://github.com/Fazik","followers_url":"https://api.github.com/users/Fazik/followers","following_url":"https://api.github.com/users/Fazik/following{/other_user}","gists_url":"https://api.github.com/users/Fazik/gists{/gist_id}","starred_url":"https://api.github.com/users/Fazik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fazik/subscriptions","organizations_url":"https://api.github.com/users/Fazik/orgs","repos_url":"https://api.github.com/users/Fazik/repos","events_url":"https://api.github.com/users/Fazik/events{/privacy}","received_events_url":"https://api.github.com/users/Fazik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-14T15:16:25Z","updated_at":"2017-11-16T17:06:01Z","closed_at":null,"author_association":"NONE","body":"Hi!\r\nI'm trying to override default User class, but it is not really clear from documentation https://websauna.org/docs/narrative/user/user.html#creating-your-own-user-class how to do that\r\n\r\nAs I understand I need to add into myapp/__init__.py copy-past of original configure_user_models(self) with changed registry.registerUtility and attach_model_to_base like\r\n`    def configure_user_models(self):\r\n        \"\"\"Plug in user models.\r\n\r\n        This initialization step connects chosen user model to SQLAlchemy model Base. Also set up :py:class:`websauna.system.user.usermixin.SiteCreator` logic - what happens when the first user logs in.\r\n        \"\"\"\r\n\r\n        from websauna.system.model.meta import Base\r\n\r\n        from websauna.system.user import models\r\n        from websauna.system.user.interfaces import IGroupModel, IUserModel, ISiteCreator\r\n        from websauna.system.user.usermixin import SiteCreator\r\n        from websauna.system.user.userregistry import DefaultEmailBasedUserRegistry\r\n        from websauna.system.user.interfaces import IActivationModel, IUserRegistry\r\n        from websauna.system.model.utils import attach_model_to_base\r\n        import myapp\r\n        attach_model_to_base(myapp.models.User, Base)\r\n        attach_model_to_base(models.Group, Base)\r\n        attach_model_to_base(models.Activation, Base)\r\n        attach_model_to_base(models.UserGroup, Base)\r\n\r\n        # Mark active user and group class\r\n        registry = self.config.registry\r\n        registry.registerUtility(myapp.models.User, IUserModel)\r\n        registry.registerUtility(models.Group, IGroupModel)\r\n        registry.registerUtility(models.Activation, IActivationModel)\r\n\r\n        site_creator = SiteCreator()\r\n        registry.registerUtility(site_creator, ISiteCreator)\r\n\r\n        # Which user registry we are using\r\n        registry.registerAdapter(factory=DefaultEmailBasedUserRegistry, required=(IRequest,), provided=IUserRegistry)\r\n\r\n\r\nin myapp.models.User I used original one from websauna/websauna/system/user/models.py\r\n\r\n`class User(usermixin.UserMixin):\r\n    \"\"\"The default user implementation for Websauna.\r\n\r\n    This is a concrete implementation of SQLAlchemy model.\r\n    \"\"\"\r\n\r\n    # In PSQL \"user\", the automatically generated table name, is a reserved word\r\n    __tablename__ = \"users\"\r\n\r\n    __init__ = _declarative_constructor\r\n\r\n    #: Current user activation instance for reset password for sign up email verification\r\n    activation_id = sa.Column(sa.Integer, sa.ForeignKey(\"user_activation.id\"))\r\n\r\n    #: SQLAlchemy relationship for above\r\n    activation = sa.orm.relationship('Activation', backref='user')\r\n\r\nwith addition of needed columns, but now I see stacktrace in admin\r\n\r\n`     \r\n    sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected - got '<class 'websauna.system.user.models.User'>'\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_debugtoolbar/panels/performance.py\", line 58, in resource_timer_handler\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] result = handler(request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_tm/__init__.py\", line 171, in tm_tween\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] reraise(*exc_info)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_tm/compat.py\", line 36, in reraise\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] raise value\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_tm/__init__.py\", line 136, in tm_tween\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = handler(request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/tweens.py\", line 41, in excview_tween\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = _error_handler(request, exc)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/tweens.py\", line 16, in _error_handler\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] reraise(*exc_info)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/compat.py\", line 148, in reraise\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] raise value\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/tweens.py\", line 39, in excview_tween\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = handler(request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/src/websauna/websauna/system/auth/tweens.py\", line 56, in __call__\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = self.handler(request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/router.py\", line 156, in handle_request\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] view_name\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/view.py\", line 642, in _call_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = view_callable(context, request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 352, in authdebug_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] return view(context, request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 301, in secured_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] return view(context, request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 513, in csrf_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] return view(context, request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 439, in rendered_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] result = view(context, request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid/viewderivers.py\", line 148, in _requestonly_view\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] response = view(request)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/src/websauna/websauna/system/admin/views.py\", line 30, in admin\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] rendered_panels = [render_panel(ma, request, name=\"admin_panel\") for id, ma in admin_panels]\r\n\r\n    File \"/usr/home/andrei/myproject/venv/src/websauna/websauna/system/admin/views.py\", line 30, in <listcomp>\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] rendered_panels = [render_panel(ma, request, name=\"admin_panel\") for id, ma in admin_panels]\r\n\r\n    File \"/usr/home/andrei/myproject/venv/src/websauna/websauna/system/core/panel.py\", line 34, in render_panel\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] return Markup(panel(context, request, *args, **kw))\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_layout/config.py\", line 242, in derived\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] result = wrapped(context, request, *args, **kw)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/pyramid_layout/config.py\", line 227, in derived\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] result = wrapped(context, request, *args, **kw)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/src/websauna/websauna/system/user/adminviews.py\", line 52, in user_admin_panel\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] count = dbsession.query(model).count()\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/sqlalchemy/orm/session.py\", line 1377, in query\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] return self._query_cls(entities, self, **kwargs)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/sqlalchemy/orm/query.py\", line 139, in __init__\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] self._set_entities(entities)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/sqlalchemy/orm/query.py\", line 148, in _set_entities\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] entity_wrapper(self, ent)\r\n\r\n    File \"/usr/home/andrei/myproject/venv/lib/python3.5/site-packages/sqlalchemy/orm/query.py\", line 3971, in __init__\r\n\r\n     [Display the sourcecode for this frame]  [Open an interactive python shell in this frame] \"expected - got '%r'\" % (column, )\r\n\r\nsqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected - got '<class 'websauna.system.user.models.User'>'\r\n\r\n`\r\n\r\nWhat I doing wrong?)\r\nSorry, I'm just starting digging in to this, so question might be slightly stupid)"},"comment":{"url":"https://api.github.com/repos/websauna/websauna/issues/comments/344990569","html_url":"https://github.com/websauna/websauna/issues/146#issuecomment-344990569","issue_url":"https://api.github.com/repos/websauna/websauna/issues/146","id":344990569,"user":{"login":"Fazik","id":13086726,"avatar_url":"https://avatars0.githubusercontent.com/u/13086726?v=4","gravatar_id":"","url":"https://api.github.com/users/Fazik","html_url":"https://github.com/Fazik","followers_url":"https://api.github.com/users/Fazik/followers","following_url":"https://api.github.com/users/Fazik/following{/other_user}","gists_url":"https://api.github.com/users/Fazik/gists{/gist_id}","starred_url":"https://api.github.com/users/Fazik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fazik/subscriptions","organizations_url":"https://api.github.com/users/Fazik/orgs","repos_url":"https://api.github.com/users/Fazik/repos","events_url":"https://api.github.com/users/Fazik/events{/privacy}","received_events_url":"https://api.github.com/users/Fazik/received_events","type":"User","site_admin":false},"created_at":"2017-11-16T17:06:01Z","updated_at":"2017-11-16T17:06:01Z","author_association":"NONE","body":"Found how to deal with requirement without overriding models, but it will be good if documentation will be extended"}}
{"actor":{"display_login":"Fazik"}}