Skip to content

Feature/moving to serverless#70

Open
danguddemi wants to merge 5 commits intomasterfrom
feature/moving-to-serverless
Open

Feature/moving to serverless#70
danguddemi wants to merge 5 commits intomasterfrom
feature/moving-to-serverless

Conversation

@danguddemi
Copy link
Collaborator

No description provided.

Signed-off-by: danguddemi <danguddemi@gmail.com>
Signed-off-by: danguddemi <danguddemi@gmail.com>
@danguddemi danguddemi added Critical A REQUIRED feature or request API labels May 27, 2019
@danguddemi danguddemi requested a review from Unix-Code May 27, 2019 06:32
@danguddemi danguddemi added this to the Initial Release milestone May 27, 2019
Signed-off-by: danguddemi <danguddemi@gmail.com>
Create LICENSE
return obj.as_dict(include_pk=False).popitem()[1]
else:
return obj.as_dict(include_pk=obj.dict_carry_pk)
return obj.as_dict(include_pk=False).popitem()[1] if obj.dict_collapse else obj.as_dict(include_pk=obj.dict_carry_pk) No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was way more readable as multiple lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

insignificant change either way

"""
get list of answerable questions
"""
page = Serverless.args.get('page', 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

int should be the third arg for page and page_size


def get_all_terms(page, page_size, order_by):
return [t.as_dict() for t in sort_and_paginate(Term.query, order_by, page, page_size).all()]
return (t.as_dict() for t in sort_and_paginate(Term.query, order_by, page, page_size).all())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

except TypeError:
raise Abort(400, f"{type} is not a valid Type")
except ValueError:
return Abort(400, f"Invalid literal {key} for type {type}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Query params should be returned as the default value if you fail to convert using type instead of returning a 400 error

results_obj = body
elif isinstance(body, list) or isinstance(body, str):
results_obj = {"data": body}
elif isinstance(body, GeneratorType):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be returning a list because list comprehension is much faster anyway. I'm fine with leaving this condition here, but it really shouldn't be hit if we can help it.

if facets:
query = apply_sql_facets(LookupQuestion, query, facets)
return [q.as_dict() for q in sort_and_paginate(query, order_by, page, page_size).all()]
return (q.as_dict() for q in sort_and_paginate(query, order_by, page, page_size).all())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

"""
get list of answerable questions
"""
page = Serverless.args.get('page', 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

page and page_size should have type as int in the Serverless.args.get(...)


def get_all_categories(page, page_size, order_by):
return [c.as_dict() for c in sort_and_paginate(QuestionCategory.query, order_by, page, page_size).all()]
return (c.as_dict() for c in sort_and_paginate(QuestionCategory.query, order_by, page, page_size).all())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

cls.logger.info(res)
return res
except Exception as e:
return responsify(f"An unknown error occurred {e}", 400)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be a 500 error code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

debatable
400 -> Client error
500 -> Server error

I figured it was more likely that the client passed in a bad argument than the server failing to do something

cls.logger.info(f"Arguments {stringParams} | {pathParams}")

try:
body, *context = func(pathParams) if pathParams else func()
Copy link
Collaborator

Choose a reason for hiding this comment

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

In Flask, it casted path parameters based on a converter i.e. <int:term_id> passed term_id into the function as an integer. I think right now the URL path parameters are being passed in as strings. Is there a way to define their types as ints or strings (if we wanted them as strings) in the serverless config?

If that's not possible, you could probably get away with just casting all the url params to ints (and if there's an error on the conversion, leave it as a string).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it returns them as strings, it doesn't automatically cast. Casting everything is a bad design decision as well, you shouldn't be using errors as conditionals/control-flow. If you need an int, you should manually cast that specific param.

@danguddemi danguddemi removed this from the Initial Release milestone Jun 7, 2019
@danguddemi
Copy link
Collaborator Author

Are we killing this PR and branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Critical A REQUIRED feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants