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

Added "enforce" field to BuildQuery, for being able of enforcing returning lists. #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jgbarah
Copy link
Member

@jgbarah jgbarah commented Sep 29, 2015

BuildQuery was returning a dictionary of lists if returned rows were larger than one, and a dictionary of elements if returned rows were exactly one. In some cases, this causes some trouble when a caller expects lists, but elements are obtained because there is only one row.

This patch adds a new parameter, "enforce", which by default is None, and can take as well the value "list". If the value is None, the previous behavior is respected, for backwards compatibility. If it is "list", a dictionary of lists is returned always.

In addition, an exception is raised if the sql string received is None, but only if enforce is "list", again for backwards compatibility.

top_questions_qaforums.py has been touched to use this new parameter, mostly as a test. All calls that expect a list should use this parameter, to avoid trouble when resulting row is one...

…rning lists.

BuildQuery was returning a dictionary of lists if returned rows were
larger than one, and a dictionary of elements if returned rows were
exactly one. In some cases, this causes some trouble when a caller
expects lists, but elements are obtained because there is only one row.

This patch adds a new parameter, "enforce", which by default is None,
and can take as well the value "list". If the value is None, the
previous behavior is respected, for backwards compatibility. If it
is "list", a dictionary of lists is returned always.

In addition, an exception is raised if the sql string received is None,
but only if enforce is "list", again for backwards compatibility.

top_questions_qaforums.py has been touched to use this new parameter,
mostly as a test. All calls that expect a list should use this
parameter, to avoid trouble when resulting row is one...
@sduenas
Copy link
Contributor

sduenas commented Sep 29, 2015

And why don't use this decorator? ccfd6f9

An example on ITS queries: 7a85be2

@jgbarah
Copy link
Member Author

jgbarah commented Sep 29, 2015

First of all, I didn't know about it ;-)

In any case, it is a bit strange/unefficient to first have specific code to "convert" into element when the list has one row, and then a decorator to convert it back to a list. But I guess it should work.

So, if the decorator is the preferred way, ok, close the pr and I will use the decorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants