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

MNTOR-3848: Fix invalid assertions #5521

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Vinnl
Copy link
Collaborator

@Vinnl Vinnl commented Jan 20, 2025

References:

Jira: MNTOR-3848
Figma:

Description

Builds on #5511, but addressing the root cause.

Knex's returning() API is intended for INSERT, UPDATE and DELETE calls, not SELECTs:
https://knexjs.org/guide/query-builder.html#returning

I've updated the .where() queries to replace the returning() calls, i.e. by making them select all columns.

I then also removed the type assertions, so as to not indicate that rows will always be returned even in cases where they might not be available.

Also, the type assertion pretended that the monthly_monitor_report_free column could only be boolean | undefined, even though it can be null too (see addUnsubcribeTokenForSubscriber, which sets it to null).

And finally, the actual root cause of the issue, the return type indicated that it would never return undefined, even though it's returning res?.[0]. I've updated that, and then fixed type errors to deal with the potentially undefined value. Question: I assumed that users without stored preferences are defaulted to be opted-in, is that correct?

(And actually I think they used to default to opted out, through undefined resolving to false. My ?? true makes them default to true.)

How to test

I'm not sure how to reproduce the original issue, so I don't know how to verify that this fixes it, but I'm fairly sure that the unit tests show what was reported.

But if someone has reproduced the issue and could verify that this fixes it, that'd be great.

Checklist (Definition of Done)

  • Localization strings (if needed) have been added.
  • Commits in this PR are minimal and have descriptive commit messages.
  • I've added or updated the relevant sections in readme and/or code comments
  • I've added a unit test to test for potential regressions of this bug.
  • If this PR implements a feature flag or experimentation, I've checked that it still works with the flag both on, and with the flag off.
  • If this PR implements a feature flag or experimentation, the Ship Behind Feature Flag status in Jira has been set
  • Product Owner accepted the User Story (demo of functionality completed) or waived the privilege.
  • All acceptance criteria are met.
  • Jira ticket has been updated (if needed) to match changes made during the development process.
  • Jira ticket has been updated (if needed) with suggestions for QA when this PR is deployed to stage.

@Vinnl Vinnl added the Review: XS Code review time: up to 30min label Jan 20, 2025
@Vinnl Vinnl requested review from rhelmer, flozia and mansaj January 20, 2025 14:01
@Vinnl Vinnl self-assigned this Jan 20, 2025
Vinnl added 2 commits January 20, 2025 15:12
Knex's returning() API is intended for INSERT, UPDATE and DELETE
calls, not SELECTs:
https://knexjs.org/guide/query-builder.html#returning

I've updated the .where() queries to replace the returning() calls,
i.e. by making them select all columns.

I then also removed the type assertions, so as to not indicate that
rows will always be returned even in cases where they might not be
available.

The type assertion also pretended that the
`monthly_monitor_report_free` column could only be
`boolean | undefined`, even though it can be `null` too (see
`addUnsubcribeTokenForSubscriber`, which sets it to `null`).
@Vinnl Vinnl force-pushed the MNTOR-3848-invalid-assertions branch from dd9d2cf to abe2549 Compare January 20, 2025 14:12
Copy link

@Vinnl Vinnl changed the title Mntor 3848 invalid assertions Fix invalid assertions Jan 20, 2025
@Vinnl Vinnl changed the title Fix invalid assertions MNTOR-3848: Fix invalid assertions Jan 20, 2025
Base automatically changed from MNTOR-3848/optional-chaining-for-monthly_monitor_report to main January 22, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review: XS Code review time: up to 30min
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants