ClimateMind / climatemind-backend

Your climate action is here 🌎 Our API is a source for learning how climate change personally affects you and the things you care about most. Additionally, it will teach a scientifically proven method for communicating to others that climate change is a personally relevant issue to inspire action.
https://contribute.climatemind.org/v/rest-api/
MIT License
18 stars 19 forks source link

Cm 499 delete account and data #501

Closed rodriguesk closed 11 months ago

rodriguesk commented 11 months ago

Detailed information:

Simply deletes user account from user account table in database.

Closing issues:

List all issues the pull request solve:

Test plan (required)

codecov-commenter commented 11 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (cd1cb16) 73.44% compared to head (b1e5564) 73.64%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ 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 ``` | [Files](https://app.codecov.io/gh/ClimateMind/climatemind-backend/pull/501?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ClimateMind) | Coverage Δ | | |---|---|---| | [app/account/schemas.py](https://app.codecov.io/gh/ClimateMind/climatemind-backend/pull/501?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ClimateMind#diff-YXBwL2FjY291bnQvc2NoZW1hcy5weQ==) | `100.00% <100.00%> (ø)` | | | [app/models.py](https://app.codecov.io/gh/ClimateMind/climatemind-backend/pull/501?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ClimateMind#diff-YXBwL21vZGVscy5weQ==) | `100.00% <100.00%> (ø)` | | | [app/account/routes.py](https://app.codecov.io/gh/ClimateMind/climatemind-backend/pull/501?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ClimateMind#diff-YXBwL2FjY291bnQvcm91dGVzLnB5) | `95.31% <87.50%> (-1.12%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/ClimateMind/climatemind-backend/pull/501/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ClimateMind)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

rodriguesk commented 11 months ago

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_functionsrule.endpoint

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 deleteop.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 https://github.com/ClimateMind/climatemind-backend/pull/501#pullrequestreview-1651751036, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXL62WSFDKNMSBHXKRDOADX5CGBNANCNFSM6AAAAAA5FKQ4HY . You are receiving this because you were mentioned.Message ID: @.***>

danmash commented 11 months ago

@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"

danmash commented 11 months ago

@Svenstar74 you could check this branch again, let me know if you still have issues

rodriguesk commented 11 months ago

@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. Could you help solve this please? It's a bit too hard for me to figure out. Here's how you can replicate manual testing to get the error I did:

  1. run in the terminal: docker-compose -p climatemind-backend --profile webapp -f docker/docker-compose.yml up -d --build
  2. Open a browser and turn on dev tools to see the developer console and access the network API calls and responses.
  3. Go to: http://localhost:3000/
  4. Use the browser to make a new fake account with email test@test.net and password testing123 and write down the session id and the JWT token
  5. Replace the JWT token and Session id in the following cURL code and run the cURL code in the terminal

curl --location 'http://localhost:5000/user-account' \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6dHJ1ZSwiaWF0IjoxNjk2Mjg3MzcyLCJqdGkiOiI0NWE2MTJjMS1lNjQyLTQyMTEtOGRlNC01OTFkMWVhMTUyYmUiLCJuYmYiOjE2OTYyODczNzIsInR5cGUiOiJhY2Nlc3MiLCJzdWIiOiJENzYzMDFGMy00MTk3LTQwMkItQjlBRS04MkYzOEYzMkFBODIiLCJleHAiOjE2OTYyOTQ1NzJ9.595EpNTEkONJJEOQCuAqP_jDASHq8S2aR-5N9lr26Lk' \ --header 'X-Session-Id: 6df9b0ad-e427-460f-b654-c680d22e9208' \ --header 'Content-Type: text/plain' \ --data '{ "currentPassword": "testing123" }'

172.23.0.1 - - [02/Oct/2023 22:57:19] "POST /user-account HTTP/1.1" 500 - Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) 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)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2464, in call return self.wsgi_app(environ, start_response) File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, kwargs))) File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(args, kwargs))) File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](req.view_args) File "/usr/local/lib/python3.8/site-packages/flask_cors/decorator.py", line 128, in wrapped_function resp = make_response(f(args, kwargs)) File "/usr/local/lib/python3.8/site-packages/flask_jwt_extended/view_decorators.py", line 115, in decorator return fn(*args, **kwargs) File "/app/app/account/routes.py", line 157, in delete_user_account current_user.delete_user() File "/app/app/models.py", line 45, in delete_user self.query.filter_by(user_uuid=self.user_uuid).delete() File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3899, in delete deleteop.exec() File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1697, in exec_ self._do_exec() File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1928, in _do_exec self._execute_stmt(delete_stmt) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1702, in _execute_stmt self.result = self.query._execute_crud(stmt, self.mapper) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3541, in _execute_crud return conn.execute(stmt, self._params) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement ret = self._execute_context( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapiexception util.raise( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) 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)') [SQL: DELETE FROM users WHERE users.user_uuid = ?] [parameters: ('D76301F3-4197-402B-B9AE-82F38F32AA82',)] (Background on this error at: http://sqlalche.me/e/13/gkpj)

rodriguesk commented 11 months ago

@danmash I don't know why pytest doesn't get these errors... ideally the unit test would actually test this part too, right?

danmash commented 11 months ago

I don't have a test account. I am unable to go beyond Q10 to create the new account.

Screenshot 2023-10-03 at 12 38 14
Svenstar74 commented 11 months ago

@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)
danmash commented 11 months ago

@Svenstar74 @rodriguesk I am still unable to test it on my local. Try the new migration I've just pushed. I think the problem here is that mssql db doesn't set ondelete action for our foreign keys. I tried the new migration and now I see the action was changed in my local db.

Screenshot 2023-10-03 at 13 03 09

Even if there are still some errors left, you could solve them by moving in this direction.

Svenstar74 commented 11 months ago

Update: It's looking good. I pulled the recent changes and also rebuilt the docker backend stuff and the account was deleted successfully. Only thing worth mentioning: Deleting may take a few seconds, so if I delete the account (and get logged out) and login immediately afterwards, I'm logged in even though the account is deleted.

danmash commented 11 months ago

note the different behaviour ondelete of the 3 foreign keys. Change if needed.

danmash commented 11 months ago

@rodriguesk feel free to merge when ready

rodriguesk commented 11 months ago

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: @.***>