Skip to content
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

fixed race conditions in the signup page #1023

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

epicadk
Copy link
Member

@epicadk epicadk commented Mar 1, 2021

Description

Fixes #1019

Type of Change:

  • Code

Code/Quality Assurance Only

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Used to same program that caught this bug to verify if it has been solved or not.

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • I have commented my code or provided relevant documentation, particularly in hard-to-understand areas

Code/Quality Assurance Only

  • My changes generate no new warnings
  • My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been published in downstream modules

@codecov
Copy link

codecov bot commented Mar 1, 2021

Codecov Report

Merging #1023 (3a29025) into develop (ca4728a) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1023      +/-   ##
===========================================
+ Coverage    92.90%   92.92%   +0.02%     
===========================================
  Files           38       38              
  Lines         2073     2079       +6     
===========================================
+ Hits          1926     1932       +6     
  Misses         147      147              
Impacted Files Coverage Δ
app/api/dao/user.py 85.88% <100.00%> (+0.05%) ⬆️
app/database/models/user.py 98.66% <100.00%> (+0.09%) ⬆️

@epicadk epicadk marked this pull request as ready for review March 1, 2021 12:39
Copy link
Contributor

@NenadPantelic NenadPantelic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @epicadk Have you tested what happens if you insert some record that will not cause integrity error, but some other form of error, e.g. DataError if the data is too long? You're catching just integrity error and rollback only in that case, we need a more general approach. DBAPIError or even Exception may help there.

@epicadk
Copy link
Member Author

epicadk commented Mar 8, 2021

Hey @epicadk Have you tested what happens if you insert some record that will not cause integrity error, but some other form of error, e.g. DataError if the data is too long? You're catching just integrity error and rollback only in that case, we need a more general approach. DBAPIError or even Exception may help there.

@NenadPantelic If the data is too long then I think we validation will not pass and it will return 400. I am not sure what other types or errors we'd want to handle. 😕 could you provide an example other than the data not matching the database constraints?

@NenadPantelic
Copy link
Contributor

Yes, in this case validators will solve the potential issue. I'm saying that we should protect the DAO layer, cause some DAO objects can be used in multiple controllers and also, we can get some unpredicted errors (transactional, persistence, etc.). In this case, I suppose it's fine on this occasion, cause validations are exhaustive and pretty much detailed and we work with the User model just from that controller, but this was more like a general comment, every layer that provides some service should be protected with its own mechanisms (like we have validations on the frontend, but we do them on the backend too and on the database).

@epicadk
Copy link
Member Author

epicadk commented Mar 8, 2021

Yes, in this case validators will solve the potential issue. I'm saying that we should protect the DAO layer, cause some DAO objects can be used in multiple controllers and also, we can get some unpredicted errors (transactional, persistence, etc.). In this case, I suppose it's fine on this occasion, cause validations are exhaustive and pretty much detailed and we work with the User model just from that controller, but this was more like a general comment, every layer that provides some service should be protected with its own mechanisms (like we have validations on the frontend, but we do them on the backend too and on the database).

I suppose we could do that. However I don't know if that would be in the scope of this pr. Feel free to open another issue. 😃

Copy link
Member

@devkapilbansal devkapilbansal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epicadk can you please include some test cases to check if this works?

@devkapilbansal devkapilbansal added the Status: Changes Requested Changes are required to be done by the PR author. label Mar 8, 2021
@epicadk epicadk added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Changes Requested Changes are required to be done by the PR author. labels Mar 9, 2021
@epicadk
Copy link
Member Author

epicadk commented Mar 9, 2021

@epicadk can you please include some test cases to check if this works?

Done 😅 .

tests/users/test_api_resources.py Outdated Show resolved Hide resolved
tests/users/test_api_resources.py Outdated Show resolved Hide resolved
@epicadk
Copy link
Member Author

epicadk commented Apr 6, 2021

Seems like github actions won't allow more than a single thread for execution. The test can't be added. Reverting the change.

@devkapilbansal
Copy link
Member

Seems like github actions won't allow more than a single thread for execution. The test can't be added. Reverting the change.

@epicadk I see the Github Workflow. There you mentioned asyncio.run(make2requests()) which is introduced in Python 3.7 but workflow uses Python 3.6 for testing. Please look into that once.

Also, resolve the conflicts

@epicadk
Copy link
Member Author

epicadk commented May 5, 2021

@epicadk I see the Github Workflow. There you mentioned asyncio.run(make2requests()) which is introduced in Python 3.7 but workflow uses Python 3.6 for testing. Please look into that once.

Doesn't matter I don't think github actions allows parallel execution of code of the tests also even if there are more than one threads it doesn't mean the code will run in parallel so it doesn't make sense to have tests for this.

Copy link
Member

@devkapilbansal devkapilbansal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Review PR needs an additional review or a maintainer's review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug : Race conditions in register endpoint.
3 participants