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

stop using MethodViews in flask apps #1102

Closed
bhearsum opened this issue Dec 20, 2019 · 3 comments · Fixed by #3092
Closed

stop using MethodViews in flask apps #1102

bhearsum opened this issue Dec 20, 2019 · 3 comments · Fixed by #3092
Labels
admin admin app & api (aus4-admin.mozilla.org) public public Balrog app/api (aus5.mozilla.org; aus-api.mozilla.org)

Comments

@bhearsum
Copy link
Contributor

Plain functions are just fine.

(Imported from https://bugzilla.mozilla.org/show_bug.cgi?id=1508137, filed by @allan-silva)

@bhearsum bhearsum added public public Balrog app/api (aus5.mozilla.org; aus-api.mozilla.org) admin admin app & api (aus4-admin.mozilla.org) labels Dec 20, 2019
@michellemounde
Copy link
Contributor

michellemounde commented Oct 25, 2023

@bhearsum I have some clarifying questions for this issue.

  1. Does this mean that in a function such as:

def scheduled_changes():
view = ScheduledChangesView("emergency_shutoff", dbo.emergencyShutoffs)
return view.get()

Instead we would have the get function that is in the ScheduledChangeView:

def get(self, where=None):
if where is None:
where = {}
if connexion.request.args.get("all") is None:
where["complete"] = False
rows = self.sc_table.select(where=where)
ret = {"count": len(rows), "scheduled_changes": []}
for row in rows:
ret["scheduled_changes"].append(add_signoff_information(row, self.table, self.sc_table))
return jsonify(ret)

  1. How would we deal with the base views that the views inherit from i.e. AdminView and HistoryView

@bhearsum
Copy link
Contributor Author

To answer the second question first -- any code that is shared by multiple views would need to be refactored to be a plain function (not a class method), which the new view functions could then call. This is actually what is already happening in emergency_shutoffs.py. It is not happening in files like

class RulesAPIView(AdminView):
, where we have a number of classes with methods on them that implement various endpoints.

(This code is connected to an endpoint name through

operationId: auslib.web.admin.views.mapper.scheduled_change_rules_get_by_id
via https://github.com/mozilla-releng/balrog/blob/ab3882c1c040770dfb779155092fe3d468571ea5/src/auslib/web/admin/views/mapper.py.)

@michellemounde
Copy link
Contributor

@bhearsum Thank you for the detailed explanation on my second question. After going through the linked files again, I now understand how plain functions would work as the base in place of the base views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admin admin app & api (aus4-admin.mozilla.org) public public Balrog app/api (aus5.mozilla.org; aus-api.mozilla.org)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants