-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix: Adds activity_id filter to answers dates query to fix problem with dataviz calendar (M2-8215) #1680
base: develop
Are you sure you want to change the base?
Conversation
…ema to fix dataviz calendar issue
➡️ Preview environment created: Click Me! |
❌ E2E tests failed |
src/apps/answers/filters.py
Outdated
@@ -34,6 +34,7 @@ class AppletSubmissionsFilter(BaseQueryParams): | |||
class AppletSubmitDateFilter(BaseQueryParams): | |||
respondent_id: uuid.UUID | None | |||
target_subject_id: uuid.UUID | None | |||
activity_id: str | None |
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'm just checking in with @ChaconC about task definition. I think this endpoint should also accept an optional activity_flow_id
. Stay tuned!
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.
Or maybe use a field named activity_or_flow_id
and in query use same code we are using in other endpoints
case(
(
AnswerSchema.flow_history_id.isnot(None),
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == str(activity_or_flow_id),
),
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) == str(activity_or_flow_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.
You should add automated tests
@@ -34,6 +34,7 @@ class AppletSubmissionsFilter(BaseQueryParams): | |||
class AppletSubmitDateFilter(BaseQueryParams): | |||
respondent_id: uuid.UUID | None | |||
target_subject_id: uuid.UUID | None | |||
activity_or_flow_id: str | None |
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.
Shouldn't this remain uuid.UUID
to maintain validation rules? I don't see anywhere else in the codebase where we type activity_or_flow_id
as str
.
Were you running into a typing issue that prompted you to switch to 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.
pleas see comment bellow
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == str(filters.activity_or_flow_id), # noqa: E501 | ||
), | ||
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) # noqa: E501 | ||
== str(filters.activity_or_flow_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.
I'm not clear why we need to convert the UUID to string. The id_from_history_id
functions return a UUID | none
type, so it should be fine to do quality comparison against another UUID | none
type, no? Maybe I'm missing something…
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == str(filters.activity_or_flow_id), # noqa: E501 | |
), | |
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) # noqa: E501 | |
== str(filters.activity_or_flow_id), | |
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == filters.activity_or_flow_id, | |
), | |
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) == filters.activity_or_flow_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.
@farmerpaul If you see this field in the database, the uuid is saved with a version in the end, causing an error parsing as uuid, that's why I had to use string instead
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.
yes, but filters.activity_or_flow_id
should be UUID, because we should validate it by pydantic, we can not accept a free format string, so original code should work, calling str(filters.activity_or_flow_id)
will have same behavior
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.
please, do not use # noqa: E501
you can break the line, use make cqf
to automatically fix this, ignoring a lint or mypy error should be always the last solution
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.
causing an error parsing as uuid, that's why I had to use string instead
@ramirlm I am not seeing any errors related to the types in my VS Code when using UUID. I'm also not seeing any errors that suggest that # noqa: E501
is needed anywhere. With the code I suggested above, everything works fine, no issues. The reason make cqf
isn't making any formatting changes is because there's no issue with the formatting, at least on my end.
I'm curious where you're seeing errors @ramirlm – is it in VS Code? Perhaps there's a configuration issue? 🤔
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.
@farmerpaul this is the error
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.
Oh, you're talking about a runtime error. I was only talking about pylance/linting errors till now, but I've reproduced your runtime error.
The error you showed is actually the result of the str()
coercion above, which is what I was trying to point out is not correct. The str()
is coercing None
(when the parameter is omitted) to a zero-length string ''
, which is not a well-formed UUID string.
When I updated the code to what I suggested above – without the str()
coercion:
(
AnswerSchema.flow_history_id.isnot(None),
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == filters.activity_or_flow_id,
),
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) == filters.activity_or_flow_id,
the error went away.
Are you seeing something different?
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, now I understood the problem here,
- without str() in filters.activity_or_flow_id, we have a comparison between str resulted from AnswerSchema.id_from_history_id() and UUID, this will not work, we should keep str()
- We should include this where clause only when filters.activity_or_flow_id is not None, it make more sense to me, because it is a optional filter
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.
@rcmerlo I don't quite follow your first bullet. According to my VS Code, AnswerSchema.id_from_history_id
returns a UUID
or None
, not a string:
So I don't see the reason for keeping str()
.
However, I agree we should omit this clause altogether if activity_or_flow_id
is None
.
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, you are right, I was confused because of hybrid_method decorator from SQLAlchemy used in this method
@@ -34,6 +34,7 @@ class AppletSubmissionsFilter(BaseQueryParams): | |||
class AppletSubmitDateFilter(BaseQueryParams): | |||
respondent_id: uuid.UUID | None | |||
target_subject_id: uuid.UUID | None | |||
activity_or_flow_id: str | None |
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.
pleas see comment bellow
@@ -295,6 +297,7 @@ async def test_list_submit_dates( | |||
respondentId=tom.id, | |||
fromDate=datetime.date.today() - datetime.timedelta(days=10), | |||
toDate=datetime.date.today() + datetime.timedelta(days=10), | |||
activityOrFlowId=applet.activities[0].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.
all tests are using only activites, please add one with a activity flow
AnswerSchema.id_from_history_id(AnswerSchema.flow_history_id) == str(filters.activity_or_flow_id), # noqa: E501 | ||
), | ||
else_=AnswerSchema.id_from_history_id(AnswerSchema.activity_history_id) # noqa: E501 | ||
== str(filters.activity_or_flow_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.
please, do not use # noqa: E501
you can break the line, use make cqf
to automatically fix this, ignoring a lint or mypy error should be always the last solution
@rcmerlo |
…bug on summary and answers page
📝 Description
🔗 Jira Ticket M2-8215
This change introduces a new (optional) field to the answers dates endpoint, which includes an additional filter to the query and removes incorrectly retrieved answers.
🪤 Peer Testing
✏️ Notes