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

fix: import events without id field #15452

Merged
merged 2 commits into from
Jul 12, 2023
Merged

fix: import events without id field #15452

merged 2 commits into from
Jul 12, 2023

Conversation

PatrykBuniX
Copy link
Contributor

@PatrykBuniX PatrykBuniX commented Jul 11, 2023

Regression introduced in #15085

There are some types of events like conversation.member-join or conversation.member-leave that do not contain "id". "id" field was typed as mandatory, while it was not true for mentioned types of events.

table.where('id').anyOf(ids).toArray() was throwing error when the list of ids contained at least one undefined value.

The fix is to type id as optional and filter out the events that do not contain id.

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #15452 (8cc2a2e) into dev (f594105) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev   #15452      +/-   ##
==========================================
+ Coverage   43.32%   43.38%   +0.06%     
==========================================
  Files         647      647              
  Lines       21831    21833       +2     
  Branches     5018     5019       +1     
==========================================
+ Hits         9458     9473      +15     
+ Misses      11154    11134      -20     
- Partials     1219     1226       +7     

@PatrykBuniX PatrykBuniX marked this pull request as ready for review July 11, 2023 12:54
@PatrykBuniX PatrykBuniX requested review from a team and otto-the-bot as code owners July 11, 2023 12:55
): Promise<number> {
if (!generateId) {
await table.bulkAdd(entities);
return entities.length;
}

const ids = entities.map(generateId);
const ids = entities.map(generateId).filter((id): id is string => id !== undefined);
Copy link
Member

Choose a reason for hiding this comment

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

If you want to ensure that if is a string, why don't you check for it instead of undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's either undefined or string in this case so doesn't really matter, but I find your idea more readable, just updated it ;)

@PatrykBuniX PatrykBuniX merged commit cc67d9a into dev Jul 12, 2023
11 checks passed
@PatrykBuniX PatrykBuniX deleted the fix/importing-backup branch July 12, 2023 07:46
thisisamir98 pushed a commit that referenced this pull request Jul 12, 2023
* fix: import events without id field

* refactor: CR suggestion
thisisamir98 added a commit that referenced this pull request Jul 12, 2023
* fix: import events without id field

* refactor: CR suggestion

Co-authored-by: Patryk Górka <patrykbunix@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants