-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add conflict check for TicketFee #5657
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
Conversation
app/api/ticket_fees.py
Outdated
| pass | ||
| else: | ||
| raise ConflictException({'pointer': ''}, | ||
| "Currency Country combination ({}-{}) already exists"\ |
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.
the backslash is redundant between brackets
|
@iamareebjamal @CosmicCoder96 Please review :) 🍻 |
- implement conflict checks for currency-country combinations - change TicketFee Factory model - add Unprocessable Entity exception for API
|
@CosmicCoder96 @iamareebjamal According to my API conditions, this particular test case should've failed. So, how do I fix that Travis build? |
app/api/ticket_fees.py
Outdated
| else: | ||
| raise UnprocessableEntity({'source': ''}, "Country or Currency cannot be NULL") | ||
| else: | ||
| raise UnprocessableEntity({'source': ''}, "Country or Currency Attribute is missing") |
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.
Use marshmallow for validation
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.
@iamareebjamal could you please elaborate?
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.
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.
Understood, shall commit soon
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.
@uds5501 I think here @iamareebjamal simply means that use allow_none=False in the schema itself. It will raise error if country or currency is missing and you can use nullable=False in model to disallow use of NULL values.
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.
@shreyanshdwivedi Ooooh! I understand now. I will update it soon
|
@iamareebjamal I was using |
|
The same thing is applied to all types of schema like event, speaker, etc. Check those. You can use before hooks but don't validate the schema there. |
|
@iamareebjamal Thanks! Fixed it now, committing |
iamareebjamal
left a comment
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.
You are still validating the schema. There should be no check for country or currency. It should be handled by Marshmallow
|
@uds5501 can you please update this ? It seems quite an important bug to me as it deals with the fees charged. |
|
@shreyanshdwivedi I will be needing some help regarding the marshmallow schema validation. As to how to determine if the new combination is present or not |
|
@uds5501 also don't validate schema where you are doing it currently. Instead use the before hooks which means functions like - open-event-server/app/api/events.py Line 143 in ad322e3
See how validate_event function is called before posting. If there is any discrepancies error is raised. Similarly you can find checks before updating the object. Implement something like this.Hope you understood 😅 |
|
@mrsaicharan1 @shreyanshdwivedi @iamareebjamal @CosmicCoder96 |
|
You can just define those in marshmallow schema for now |
|
@iamareebjamal understood, shall do that |
|
@iamareebjamal @shreyanshdwivedi Please review |
app/api/schema/ticket_fees.py
Outdated
| id = fields.Integer(dump_only=True) | ||
| currency = fields.Str(validate=validate.OneOf(choices=PAYMENT_CURRENCY_CHOICES), allow_none=True) | ||
| country = fields.String(allow_none=True) | ||
| currency = fields.Str(validate=validate.OneOf(choices=PAYMENT_CURRENCY_CHOICES), allow_none=False, default='USD') |
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.
Don't default to USD. We need the user to provide the values. There is no UI showing the user that it will default to USD if no value is provided
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.
@iamareebjamal So I should use no default value?
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.
Yes
|
@iamareebjamal I have removed the default values from schema, does anything else needs to be done now? |
app/api/ticket_fees.py
Outdated
| if (data['country'] and data['currency']): | ||
| try: | ||
| already_existing_combination = TicketFees.query.filter_by(country=data['country'], | ||
| currency=data['currency']).one() |
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.
Just add a unique key on country and currency. No need for this check
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.
@iamareebjamal A unique key constraint would ensure that I don't get to save similar values of the same column.
I want to be able to save :USA - USD and USA-INR combination simultaneously. I don't think adding unique constraints would allow that
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.
You are simulating unique key constraint on TicketFee, if unique key won't work, this shouldn't work too
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.
You are ensuring that country and currency pair is unique and not repeated. That's the work on unique key
|
@uds5501 similar to my PR, this is failing due to multiple heads. Please fix it |
|
@shreyanshdwivedi do i need to change the |
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'cb4ccda76a2b' | ||
| down_revision = '0e80c49a6e28' |
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.
@uds5501 change down_revision and revises to Revision ID of migration in my latest merged PR
|
@shreyanshdwivedi this PR won't work until the dredd hook request is fixed. I am opening an issue to fix this request : |
iamareebjamal
left a comment
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.
You have to add composite unique key on country and currency if I understand correctly. Shouldn't I be able to have ('UK', 'GBP') and ('UK', 'EUR')?
|
@iamareebjamal you are right, I will look for corresponding resources and update this soon |
|
Closed in favour of #6017 |


Fixes fossasia/open-event-frontend#2169
Checklist
developmentbranch.Short description of what this resolves:
this makes sure no more than 1 object of a particular Currency-Country combination is being formed
Changes proposed in this pull request: