-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
refactor: remove repetitive safe_query #7017
refactor: remove repetitive safe_query #7017
Conversation
app/api/tracks.py
Outdated
@@ -1,7 +1,7 @@ | |||
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | |||
|
|||
from app.api.bootstrap import api | |||
from app.api.helpers.db import safe_query | |||
from app.api.helpers.db import safe_query, safe_query_kwargs |
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.
'app.api.helpers.db.safe_query' imported but unused
app/api/session_types.py
Outdated
@@ -1,7 +1,7 @@ | |||
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | |||
|
|||
from app.api.bootstrap import api | |||
from app.api.helpers.db import safe_query | |||
from app.api.helpers.db import safe_query, safe_query_kwargs |
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.
'app.api.helpers.db.safe_query' imported but unused
app/api/microlocations.py
Outdated
@@ -1,7 +1,7 @@ | |||
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | |||
|
|||
from app.api.bootstrap import api | |||
from app.api.helpers.db import safe_query | |||
from app.api.helpers.db import safe_query, safe_query_kwargs |
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.
'app.api.helpers.db.safe_query' imported but unused
app/api/helpers/db.py
Outdated
parameter_name, | ||
# TODO(Areeb): Check that only admin can pass this parameter | ||
request.args.get('get_trashed') != 'true', | ||
) |
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.
no newline at end of file
app/api/helpers/db.py
Outdated
@@ -129,3 +129,21 @@ def get_new_slug(model, name): | |||
return slug | |||
else: | |||
return '{}-{}'.format(slug, uuid.uuid4().hex) | |||
|
|||
def safe_query_kwargs(model, kwargs, parameter_name): |
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.
expected 2 blank lines, found 1
Codecov Report
@@ Coverage Diff @@
## development #7017 +/- ##
===============================================
- Coverage 60.55% 60.55% -0.01%
===============================================
Files 260 260
Lines 12875 12877 +2
===============================================
+ Hits 7797 7798 +1
- Misses 5078 5079 +1
Continue to review full report at Codecov.
|
app/api/helpers/db.py
Outdated
@@ -129,3 +129,21 @@ def get_new_slug(model, name): | |||
return slug | |||
else: | |||
return '{}-{}'.format(slug, uuid.uuid4().hex) | |||
|
|||
def safe_query_kwargs(model, kwargs, parameter_name): |
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.
Wrong place to add the method
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.
Where should I place this method?
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.
Near others
Fix hound and codacy issues |
app/api/helpers/db.py
Outdated
message eg 'event_id' | ||
:return: | ||
""" | ||
return safe_query_without_soft_deleted_entries( |
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 replacing safe_query
method, so you should use it instead, not safe_query_without_soft_deleted_entries
And move it above safe_query_without_soft_deleted_entries
Great job, but a lot of safe_query calls are still remaining |
Yes, do I cover all safe_query calls in this PR? |
Yes, obviously the issue will only be resolved once all such calls are handled |
Ok |
Also, calls like this are very similar: safe_query(EventInvoice, 'identifier', view_kwargs['event_invoice_identifier'], 'event_invoice_identifier') The only difference is |
ok |
app/api/orders.py
Outdated
@@ -631,7 +632,7 @@ def before_get(self, args, kwargs): | |||
) | |||
kwargs['id'] = order.id | |||
elif kwargs.get('id'): | |||
order = safe_query(Order, 'id', kwargs['id'], 'id') | |||
order = safe_query_kwargs(Order, kwargs, 'id') |
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 safe_query_by_id
here
Great job. Final thing, please change the PR title to match semantic guidelines, see other merged PRs for reference |
@@ -16,6 +16,8 @@ | |||
from app.api.helpers.db import ( | |||
safe_query, | |||
save_to_db, | |||
safe_query_kwargs, | |||
safe_query_by_id |
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.
Black would make changes.
Here is an overview of what got changed by this pull request: Clones removed
==============
+ app/api/event_topics.py -1
+ app/api/event_copyright.py -1
+ app/api/feedbacks.py -2
+ app/api/custom_forms.py -2
+ app/api/event_types.py -1
+ app/api/tax.py -2
+ app/api/tickets.py -1
+ app/api/event_sub_topics.py -1
See the complete overview on Codacy |
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.
Great Job!
Thank you so much. |
Fixes #7001
Short description of what this resolves:
change the all safe_query(db, Session, 'id', view_kwargs['session_id'], 'session_id') into safe_query_kwargs(Session, view_kwargs, 'session_id')
Changes proposed in this pull request:
Checklist
development
branch.