Skip to content

Conversation

@shreyanshdwivedi
Copy link
Member

Fixes #5986

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

Short description of what this resolves:

Invitations with the same email and same role can be sent more than once and it is being stored multiple times in the list of roles.

Changes proposed in this pull request:

  • Raises error when duplicate role invite is created

@codecov
Copy link

codecov bot commented Jun 5, 2019

Codecov Report

Merging #6000 into development will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           development    #6000   +/-   ##
============================================
  Coverage        66.28%   66.28%           
============================================
  Files              285      285           
  Lines            13995    13995           
============================================
  Hits              9277     9277           
  Misses            4718     4718

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b66321...94cf67a. Read the comment docs.

@shreyanshdwivedi shreyanshdwivedi changed the title [WIP] fix: raises error when duplicate role invite is created fix: raises error when duplicate role invite is created Jun 5, 2019
@auto-label auto-label bot added the fix label Jun 5, 2019
@shreyanshdwivedi shreyanshdwivedi force-pushed the roleInvite branch 2 times, most recently from a524946 to 10a9fb3 Compare June 6, 2019 04:16
@shreyanshdwivedi shreyanshdwivedi force-pushed the roleInvite branch 2 times, most recently from 83b9b1f to 4b341dd Compare June 6, 2019 04:46
Copy link
Member

@iamareebjamal iamareebjamal left a comment

Choose a reason for hiding this comment

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

Use unique constraint

@shreyanshdwivedi
Copy link
Member Author

@iamareebjamal you mean this -
__table_args__ = (UniqueConstraint('email', 'role_id', 'event_id',name='email_role_event_uc'), ) ?
I tested it locally but the postman didn't raise error. However will check again.
Maybe @uds5501 @kushthedude can test locally too?

@iamareebjamal
Copy link
Member

iamareebjamal commented Jun 6, 2019

You are checking uniqueness on 3 attributes, email, role and event_id whereas the Unique Constraint has 4 attributes, that's why it's not failing

@shreyanshdwivedi
Copy link
Member Author

@iamareebjamal actually I followed the implementation from here -

__table_args__ = (UniqueConstraint('event_id', 'field_identifier', 'form', name='custom_form_identifier'), )

Maybe this needs to be fixed too.

@iamareebjamal
Copy link
Member

I'm sorry, I was wrong, the unique constraint is correct. You just haven't created the migration. How is the DB going to know about the constraint?

@shreyanshdwivedi shreyanshdwivedi changed the title fix: raises error when duplicate role invite is created fix: adds unique constraint on role_invite Jun 6, 2019
uds5501
uds5501 previously approved these changes Jun 6, 2019
Copy link
Contributor

@uds5501 uds5501 left a comment

Choose a reason for hiding this comment

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

This looks good!

@shreyanshdwivedi
Copy link
Member Author

@iamareebjamal thanks a lot for help. I've fixed it.
Please review :)

WHERE R1.id < R2.id
AND R1.email = R2.email
AND R1.role_id = R2.role_id
AND R1.event_id = R2.event_id
Copy link
Member

Choose a reason for hiding this comment

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

Uhh, what?

Copy link
Member

Choose a reason for hiding this comment

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

Removing duplicates, right?

So are there any foreign keys in role_invites?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm deleting all the past duplicate entries here and tested on my local too. When I didn't add this delete condition the upgradation raised error due to presence of duplicate entries. Is the delete statement wrong? @iamareebjamal

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes @iamareebjamal. event_id and role_id are foreignKeys

event_id = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE'))

Copy link
Member

Choose a reason for hiding this comment

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

No, which table has role_invites as foreign key?

Copy link
Member

Choose a reason for hiding this comment

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

I'm deleting all the past duplicate entries here and tested on my local too

Problem is about data loss in production DB, if one of the deleted role invite is linked to other table

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal I understand your concern. I've cross-checked and didn't find any model which uses role_invite as a foreign key.

Copy link
Member

@iamareebjamal iamareebjamal Jun 6, 2019

Choose a reason for hiding this comment

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

OK, so reverse the condition R1.id > R2.id, we want to delete all but first

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal changed the condition.

@iamareebjamal iamareebjamal merged commit eaf70d6 into fossasia:development Jun 6, 2019
@shreyanshdwivedi shreyanshdwivedi deleted the roleInvite branch June 14, 2019 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple role invitations to the same email are allowed and are stored multiple times

4 participants