Feature/806 add label filter and sort content by label in contents endpoint #45
Feature/806 add label filter and sort content by label in contents endpoint #45
Conversation
Pull Request Test Coverage Report for Build 775
💛 - Coveralls |
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.
content_type: str=CONTENT_TYPES.Any_SLUG, | ||
workspace: Workspace=None, | ||
label: str=None, | ||
order_by_label=False |
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.
I agree with 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.
Done.
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.
last change request
…6_add_label_filter_and_sort_content_by_label_in_contents_endpoint
workspace: Workspace = None | ||
workspace: Workspace = None, | ||
label:str = None, | ||
order_by_properties: typing.List[str] = (), |
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.
Type hint is wrong. It should by typing.List[Column], doesnt it?
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.
Currently no, we currently pass strings to "order_by" function of sqlalchemy.
We can also pass Column, complex sql subquery and probably others thing to this function, but as we have string in entry from endpoint and that string work for ordering, i do not think about casting this to Column.
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.
@inkhey the part of code I looked at was something like .order_by(Content.label)
. Do you really pass strings? If so, what is the string content?
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.
$ grep -r order_by *
backend/tracim_backend/lib/core/group.py: return self._base_query().order_by(Group.group_id).all()
backend/tracim_backend/lib/core/workspace.py: workspaces = self._base_query().order_by(Workspace.label).all()
backend/tracim_backend/lib/core/workspace.py: .order_by(Workspace.label) \
backend/tracim_backend/lib/core/user.py: return self._session.query(User).order_by(User.display_name)
backend/tracim_backend/lib/core/userworkspace.py: # def get_all_for_user_order_by_workspace(
backend/tracim_backend/lib/core/userworkspace.py: # .join(UserRoleInWorkspace.workspace).order_by(Workspace.label).all()
backend/tracim_backend/lib/core/content.py: .order_by(ContentRevisionRO.revision_id.desc())
backend/tracim_backend/lib/core/content.py: .order_by(
backend/tracim_backend/lib/core/content.py: .order_by(Content.revision_id.desc()) \
backend/tracim_backend/lib/core/content.py: resultset = resultset.order_by(desc(Content.updated))
backend/tracim_backend/lib/core/content.py: # .order_by(desc(Content.updated))
backend/tracim_backend/models/data.py: order_by="ContentRevisionRO.revision_id")
backend/tracim_backend/tests/models/test_content.py: .order_by(ContentRevisionRO.revision_id.desc())\
backend/tracim_backend/tests/library/test_webdav.py: .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(Content.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(ContentRevisionRO.revision_id.desc()) \
backend/tracim_backend/tests/library/test_webdav.py: .order_by(ContentRevisionRO.revision_id.desc()) \
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're right, in fact, i pass "Content.label" which is "'hybrid_propertyProxy" .... i just tried with passing "label" and it work also.
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.
Actually, the problem is that typing must help developer to understand the code. If the typing is defined as "string", the developer has no information about what to give as a parameter. I see 2 possibilities :
- improve typing (the best solution)
- add docstring
Maybe both must be implemented.
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.
problem i see is that typing who should allowed here is clearly unclear.
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.
ok. so I suggest you set the typing to "str or hybrid_propertyProxy", and you add docstring explaining that the recommanded way to use it is to pass Model.attribute
.
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.
as soos as you fix this, tell me (or @buxx) to merge the MR
content_type: str=CONTENT_TYPES.Any_SLUG, | ||
workspace: Workspace=None, | ||
label: str=None, | ||
order_by_properties: typing.List[str] = () |
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.
Type hint is wrong. It should by typing.List[Column], doesnt it?
…6_add_label_filter_and_sort_content_by_label_in_contents_endpoint
workspace: Workspace = None | ||
workspace: Workspace = None, | ||
label:str = None, | ||
order_by_properties: typing.List[typing.Union[str, QueryableAttribute]] = (), |
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 is some problems here:
- typing say List, default value is a tuple (it should be empty list)
- we can't give an list instance here, example:
>>> def foo(a=[]):
... a.append(1)
... print(a)
...
>>> foo()
[1]
>>> foo()
[1, 1]
>>> foo()
[1, 1, 1]
>>> foo()
[1, 1, 1, 1]
Prefer:
def foo(a=None):
a = a or [] # FDV
FDV = Forced Default Value
related to tracim/tracim#806