-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Cm 499 delete account and data #501
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## develop #501 +/- ##
===========================================
+ Coverage 73.44% 73.64% +0.20%
===========================================
Files 82 82
Lines 2598 2618 +20
Branches 314 315 +1
===========================================
+ Hits 1908 1928 +20
Misses 657 657
Partials 33 33
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rodriguesk , nicely done 👍 the PR seems valid, the only difference with the requirement I see is that you are using POST instead of DELETE, but I think this is fine.
According to docs conversations will be stored in the db after user deletion with null value
https://docs.sqlalchemy.org/en/20/orm/cascades.html#delete
Hi @danmash
The front end is reporting getting this error from the database when using
this branch and testing to delete a user account:
2023-09-25 10:01:19 172.18.0.1 - - [25/Sep/2023 08:01:19] "POST
/user-account HTTP/1.1" 500 -
2023-09-25 10:01:19 Traceback (most recent call last):
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1276, in _execute_context
2023-09-25 10:01:19 self.dialect.do_execute(
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line
593, in do_execute
2023-09-25 10:01:19 cursor.execute(statement, parameters)
2023-09-25 10:01:19 pyodbc.IntegrityError: ('23000', '[23000]
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The DELETE statement
conflicted with the REFERENCE constraint "fk_sessions__user_uuid__users".
The conflict occurred in database "sqldb-web-prod-001", table
"dbo.sessions", column \'user_uuid\'. (547) (SQLExecDirectW)')
2023-09-25 10:01:19
2023-09-25 10:01:19 The above exception was the direct cause of the
following exception:
2023-09-25 10:01:19
2023-09-25 10:01:19 Traceback (most recent call last):
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 2464, in
__call__
2023-09-25 10:01:19 return self.wsgi_app(environ, start_response)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 2450, in
wsgi_app
2023-09-25 10:01:19 response = self.handle_exception(e)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165,
in wrapped_function
2023-09-25 10:01:19 return
cors_after_request(app.make_response(f(*args, **kwargs)))
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 1867, in
handle_exception
2023-09-25 10:01:19 reraise(exc_type, exc_value, tb)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in
reraise
2023-09-25 10:01:19 raise value
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in
wsgi_app
2023-09-25 10:01:19 response = self.full_dispatch_request()
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in
full_dispatch_request
2023-09-25 10:01:19 rv = self.handle_user_exception(e)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165,
in wrapped_function
2023-09-25 10:01:19 return
cors_after_request(app.make_response(f(*args, **kwargs)))
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in
handle_user_exception
2023-09-25 10:01:19 reraise(exc_type, exc_value, tb)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in
reraise
2023-09-25 10:01:19 raise value
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in
full_dispatch_request
2023-09-25 10:01:19 rv = self.dispatch_request()
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in
dispatch_request
2023-09-25 10:01:19 return
self.view_functions[rule.endpoint](**req.view_args)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask_cors/decorator.py", line 128,
in wrapped_function
2023-09-25 10:01:19 resp = make_response(f(*args, **kwargs))
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/flask_jwt_extended/view_decorators.py",
line 115, in decorator
2023-09-25 10:01:19 return fn(*args, **kwargs)
2023-09-25 10:01:19 File "/app/app/account/routes.py", line 157, in
delete_user_account
2023-09-25 10:01:19 current_user.delete_user()
2023-09-25 10:01:19 File "/app/app/models.py", line 42, in delete_user
2023-09-25 10:01:19
self.query.filter_by(user_uuid=self.user_uuid).delete()
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line
3899, in delete
2023-09-25 10:01:19 delete_op.exec_()
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py",
line 1697, in exec_
2023-09-25 10:01:19 self._do_exec()
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py",
line 1928, in _do_exec
2023-09-25 10:01:19 self._execute_stmt(delete_stmt)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py",
line 1702, in _execute_stmt
2023-09-25 10:01:19 self.result = self.query._execute_crud(stmt,
self.mapper)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line
3541, in _execute_crud
2023-09-25 10:01:19 return conn.execute(stmt, self._params)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1011, in execute
2023-09-25 10:01:19 return meth(self, multiparams, params)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line
298, in _execute_on_connection
2023-09-25 10:01:19 return connection._execute_clauseelement(self,
multiparams, params)
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1124, in _execute_clauseelement
2023-09-25 10:01:19 ret = self._execute_context(
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1316, in _execute_context
2023-09-25 10:01:19 self._handle_dbapi_exception(
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1510, in _handle_dbapi_exception
2023-09-25 10:01:19 util.raise_(
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line
182, in raise_
2023-09-25 10:01:19 raise exception
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line
1276, in _execute_context
2023-09-25 10:01:19 self.dialect.do_execute(
2023-09-25 10:01:19 File
"/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line
593, in do_execute
2023-09-25 10:01:19 cursor.execute(statement, parameters)
2023-09-25 10:01:19 sqlalchemy.exc.IntegrityError: (pyodbc.IntegrityError)
('23000', '[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL
Server]The DELETE statement conflicted with the REFERENCE constraint
"fk_sessions__user_uuid__users". The conflict occurred in database
"sqldb-web-prod-001", table "dbo.sessions", column \'user_uuid\'. (547)
(SQLExecDirectW)')
2023-09-25 10:01:19 [SQL: DELETE FROM users WHERE users.user_uuid = ?]
2023-09-25 10:01:19 [parameters: ('35FEDABF-A881-4A98-8191-BFEECEDE06EC',)]
2023-09-25 10:01:19 (Background on this error at:
http://sqlalche.me/e/13/gkpj)
…On Sat, Sep 30, 2023 at 2:35 PM Daniil Mashkin ***@***.***> wrote:
*External Email*
***@***.**** approved this pull request.
Hi @rodriguesk <https://github.com/rodriguesk> , nicely done 👍 the PR
seems valid, the only difference with the requirement I see is that you are
using POST instead of DELETE, but I think this is fine.
According to docs conversations will be stored in the db after user
deletion with null value
https://docs.sqlalchemy.org/en/20/orm/cascades.html#delete
—
Reply to this email directly, view it on GitHub
<#501 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEXL62WSFDKNMSBHXKRDOADX5CGBNANCNFSM6AAAAAA5FKQ4HY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@rodriguesk I am unable to test my change on local due to API errors, I think the solution here is ondelete="SET NULL", because looks like the MSSQL default action is "NO ACTION" |
@Svenstar74 you could check this branch again, let me know if you still have issues |
@danmash I did the flask db upgrade and removed the database volume and rebuilt the dockers and then tested your code changes using postman and still am getting the error shown below.
curl --location 'http://localhost:5000/user-account' 172.23.0.1 - - [02/Oct/2023 22:57:19] "POST /user-account HTTP/1.1" 500 - The above exception was the direct cause of the following exception: Traceback (most recent call last): |
@danmash I don't know why pytest doesn't get these errors... ideally the unit test would actually test this part too, right? |
@danmash It seems like the error still occurs: 2023-10-03 13:42:57 172.18.0.1 - - [03/Oct/2023 11:42:57] "POST /user-account HTTP/1.1" 500 -
2023-10-03 13:42:57 Traceback (most recent call last):
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
2023-10-03 13:42:57 self.dialect.do_execute(
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
2023-10-03 13:42:57 cursor.execute(statement, parameters)
2023-10-03 13:42:57 pyodbc.IntegrityError: ('23000', '[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The DELETE statement conflicted with the REFERENCE constraint "fk_sessions__user_uuid__users". The conflict occurred in database "sqldb-web-prod-001", table "dbo.sessions", column \'user_uuid\'. (547) (SQLExecDirectW)')
2023-10-03 13:42:57
2023-10-03 13:42:57 The above exception was the direct cause of the following exception:
2023-10-03 13:42:57
2023-10-03 13:42:57 Traceback (most recent call last):
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
2023-10-03 13:42:57 return self.wsgi_app(environ, start_response)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
2023-10-03 13:42:57 response = self.handle_exception(e)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
2023-10-03 13:42:57 return cors_after_request(app.make_response(f(*args, **kwargs)))
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
2023-10-03 13:42:57 reraise(exc_type, exc_value, tb)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
2023-10-03 13:42:57 raise value
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
2023-10-03 13:42:57 response = self.full_dispatch_request()
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
2023-10-03 13:42:57 rv = self.handle_user_exception(e)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
2023-10-03 13:42:57 return cors_after_request(app.make_response(f(*args, **kwargs)))
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
2023-10-03 13:42:57 reraise(exc_type, exc_value, tb)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
2023-10-03 13:42:57 raise value
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
2023-10-03 13:42:57 rv = self.dispatch_request()
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
2023-10-03 13:42:57 return self.view_functions[rule.endpoint](**req.view_args)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask_cors/decorator.py", line 128, in wrapped_function
2023-10-03 13:42:57 resp = make_response(f(*args, **kwargs))
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/flask_jwt_extended/view_decorators.py", line 115, in decorator
2023-10-03 13:42:57 return fn(*args, **kwargs)
2023-10-03 13:42:57 File "/app/app/account/routes.py", line 157, in delete_user_account
2023-10-03 13:42:57 current_user.delete_user()
2023-10-03 13:42:57 File "/app/app/models.py", line 45, in delete_user
2023-10-03 13:42:57 self.query.filter_by(user_uuid=self.user_uuid).delete()
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3899, in delete
2023-10-03 13:42:57 delete_op.exec_()
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1697, in exec_
2023-10-03 13:42:57 self._do_exec()
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1928, in _do_exec
2023-10-03 13:42:57 self._execute_stmt(delete_stmt)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1702, in _execute_stmt
2023-10-03 13:42:57 self.result = self.query._execute_crud(stmt, self.mapper)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3541, in _execute_crud
2023-10-03 13:42:57 return conn.execute(stmt, self._params)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
2023-10-03 13:42:57 return meth(self, multiparams, params)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
2023-10-03 13:42:57 return connection._execute_clauseelement(self, multiparams, params)
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
2023-10-03 13:42:57 ret = self._execute_context(
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
2023-10-03 13:42:57 self._handle_dbapi_exception(
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
2023-10-03 13:42:57 util.raise_(
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
2023-10-03 13:42:57 raise exception
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
2023-10-03 13:42:57 self.dialect.do_execute(
2023-10-03 13:42:57 File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
2023-10-03 13:42:57 cursor.execute(statement, parameters)
2023-10-03 13:42:57 sqlalchemy.exc.IntegrityError: (pyodbc.IntegrityError) ('23000', '[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The DELETE statement conflicted with the REFERENCE constraint "fk_sessions__user_uuid__users". The conflict occurred in database "sqldb-web-prod-001", table "dbo.sessions", column \'user_uuid\'. (547) (SQLExecDirectW)')
2023-10-03 13:42:57 [SQL: DELETE FROM users WHERE users.user_uuid = ?]
2023-10-03 13:42:57 [parameters: ('65510044-9406-4D68-A505-29A84EA7D50B',)]
2023-10-03 13:42:57 (Background on this error at: http://sqlalche.me/e/13/gkpj) |
@Svenstar74 @rodriguesk I am still unable to test it on my local. Try the new migration I've just pushed. Even if there are still some errors left, you could solve them by moving in this direction. |
Update: It's looking good. |
note the different behaviour ondelete of the 3 foreign keys. Change if needed. |
@rodriguesk feel free to merge when ready |
Ok, I’m thinking I should switch the method to DELETE before merging.On Oct 6, 2023, at 4:46 AM, Daniil Mashkin ***@***.***> wrote:External Email
@rodriguesk feel free to merge when ready
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
…elete-account-and-data
* Removed flask-selfdoc from project. * Update score_nodes.py added relatedPersonalValues to the GET response of the /feed endpoint to include all the personal values associated with each climate change impact for user's feed. * run linting * optional parameter to skip recaptcha * change spelling * remove timedelta * Update installation.md instructions how to free up port 5000 on macs. * Cm 499 delete account and data (#501) * Black formatting * Extra test to ensure deleted user can't login * added api documentation * #499 ondelete="SET NULL" or "CASCADE" * #499 explicit ondelete action for user foreign keys * Change route method from POST to DELETE * switch POST documentation to DELETE in app/static/Climate-Mind_bundled.yml --------- Co-authored-by: Daniil Mashkin <dm@zint.io> Co-authored-by: Daniil Mashkin <danmash@users.noreply.github.com> --------- Co-authored-by: Jason Hutson <110316760+HutsonJason@users.noreply.github.com> Co-authored-by: Svenstar74 <sven.firmbach@gmx.de> Co-authored-by: Daniil Mashkin <dm@zint.io> Co-authored-by: Daniil Mashkin <danmash@users.noreply.github.com>
* Removed flask-selfdoc from project. * Update score_nodes.py added relatedPersonalValues to the GET response of the /feed endpoint to include all the personal values associated with each climate change impact for user's feed. * run linting * optional parameter to skip recaptcha * change spelling * remove timedelta * Update installation.md instructions how to free up port 5000 on macs. * Cm 499 delete account and data (#501) * Black formatting * Extra test to ensure deleted user can't login * added api documentation * #499 ondelete="SET NULL" or "CASCADE" * #499 explicit ondelete action for user foreign keys * Change route method from POST to DELETE * switch POST documentation to DELETE in app/static/Climate-Mind_bundled.yml --------- Co-authored-by: Daniil Mashkin <dm@zint.io> Co-authored-by: Daniil Mashkin <danmash@users.noreply.github.com> * Analytics endpoint (#504) * Initial commit for #503 * Modified 2 files * Fixing some bugs * Remove init not needed Remove * Fixed bugs * clearer datetime string format documentation. * Fixed bug with date time * Lint * #503 unittests fixed --------- Co-authored-by: Daniil Mashkin <dm@zint.io> --------- Co-authored-by: Jason Hutson <110316760+HutsonJason@users.noreply.github.com> Co-authored-by: Svenstar74 <sven.firmbach@gmx.de> Co-authored-by: Daniil Mashkin <dm@zint.io> Co-authored-by: Daniil Mashkin <danmash@users.noreply.github.com>
Detailed information:
Simply deletes user account from user account table in database.
Closing issues:
List all issues the pull request solve:
closes delete account and associated data #499
Test plan (required)