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 error caused by undefined "trackedQuery" in QueryManager #8570

Merged

Conversation

stephenarosaj
Copy link
Contributor

  • Add check for non-query refType in executeQuery that throws error on refType mismatch
  • Add unit test to check for properly thrown error in case that executeQuery receives non-query refType, and doesn't throw error when receiving query refType

@stephenarosaj stephenarosaj requested a review from a team as a code owner October 15, 2024 17:30
Copy link

changeset-bot bot commented Oct 15, 2024

🦋 Changeset detected

Latest commit: d4de37a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/data-connect Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v4.0

@stephenarosaj stephenarosaj requested review from a team as code owners October 15, 2024 17:42
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 15, 2024

Size Report 1

Affected Products

  • @firebase/data-connect

    TypeBase (2e28041)Merge (3cfd8ab)Diff
    browser19.8 kB19.9 kB+131 B (+0.7%)
    esm522.5 kB22.6 kB+131 B (+0.6%)
    main24.3 kB24.4 kB+131 B (+0.5%)
    module19.8 kB19.9 kB+131 B (+0.7%)
  • firebase

    TypeBase (2e28041)Merge (3cfd8ab)Diff
    firebase-data-connect.js16.5 kB16.6 kB+101 B (+0.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/pS10EOtq0E.html

);

expect(() => qm.executeQuery(mutationRef)).to.throw(error.message);
expect(() => qm.executeQuery(queryRef)).to.not.throw(error.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just be able to call executeQuery(dc, queryRef) here and similarly the line before, though I'd recommend renaming both of those variables to prevent conflicts with the queryRef and mutationRef functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

refType: MUTATION_STR as 'query'
};

const queryRef: QueryRef<string, string> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend creating a queryRef the same way that most users do: by calling queryRef(dc, queryName);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

});

const mutationRef: QueryRef<string, string> = {
name: 'm',
Copy link
Contributor

Choose a reason for hiding this comment

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

Call mutationRef here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

const rt = new RESTTransport(options, undefined, undefined, authProvider);
const qm = new QueryManager(rt);
const app = initializeApp({ projectId: 'p' });
const dc = getDataConnect(app, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clean these up in an afterEach, like here:

beforeEach(() => {
initializeFetch(fakeFetchImpl);
app = initializeApp({ projectId: 'p', appId: APPID }, 'fdsasdf'); // TODO(mtewani): Replace with util function
dc = getDataConnect(app, { connector: 'c', location: 'l', service: 's' });
});
afterEach(async () => {
await dc._delete();
await deleteApp(app);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 15, 2024

Size Analysis Report 1

Affected Products

  • @firebase/data-connect

    • DataConnect

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.9%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • MUTATION_STR

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.8%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • MutationManager

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.8%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • QUERY_STR

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.9%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • SOURCE_CACHE

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.9%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • SOURCE_SERVER

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.8%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • connectDataConnectEmulator

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.7 kB29.8 kB+101 B (+0.3%)
    • executeMutation

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.7 kB29.8 kB+101 B (+0.3%)
    • executeQuery

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.7 kB29.8 kB+101 B (+0.3%)
    • getDataConnect

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size12.2 kB12.3 kB+98 B (+0.8%)
      size-with-ext-deps37.4 kB37.5 kB+101 B (+0.3%)
    • mutationRef

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.7 kB29.8 kB+101 B (+0.3%)
    • parseOptions

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.5 kB11.6 kB+98 B (+0.9%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • queryRef

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.7 kB29.8 kB+101 B (+0.3%)
    • setLogLevel

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • subscribe

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size12.8 kB12.9 kB+98 B (+0.8%)
      size-with-ext-deps37.9 kB38.0 kB+101 B (+0.3%)
    • terminate

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.6 kB11.7 kB+98 B (+0.8%)
      size-with-ext-deps29.6 kB29.7 kB+101 B (+0.3%)
    • toQueryRef

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size12.4 kB12.5 kB+98 B (+0.8%)
      size-with-ext-deps37.6 kB37.7 kB+101 B (+0.3%)
    • validateArgs

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size12.4 kB12.5 kB+98 B (+0.8%)
      size-with-ext-deps37.5 kB37.6 kB+101 B (+0.3%)
    • validateDCOptions

      Size

      TypeBase (2e28041)Merge (3cfd8ab)Diff
      size11.8 kB11.9 kB+98 B (+0.8%)
      size-with-ext-deps29.8 kB29.9 kB+101 B (+0.3%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/KOmOl4B5fR.html

Copy link
Contributor Author

@stephenarosaj stephenarosaj left a comment

Choose a reason for hiding this comment

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

Accepted changes to new unit test proposed by @maneesht in review

const rt = new RESTTransport(options, undefined, undefined, authProvider);
const qm = new QueryManager(rt);
const app = initializeApp({ projectId: 'p' });
const dc = getDataConnect(app, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

});

const mutationRef: QueryRef<string, string> = {
name: 'm',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

refType: MUTATION_STR as 'query'
};

const queryRef: QueryRef<string, string> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

);

expect(() => qm.executeQuery(mutationRef)).to.throw(error.message);
expect(() => qm.executeQuery(queryRef)).to.not.throw(error.message);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit a0ecb6f

---

- Add check for non-query refType in `executeQuery` that throws error on refType mismatch
- Add unit test to check that error is thrown when `executeQuery` receives non-query refType, and not thrown otherwise
Copy link
Contributor

Choose a reason for hiding this comment

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

Changelogs get added to release notes, and the unit tests aren't really relevant. Can we say something like:
Throw error when calling executeQuery with mutations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted in commit d4de37a

@stephenarosaj stephenarosaj merged commit cf988b0 into main Oct 15, 2024
39 checks passed
@stephenarosaj stephenarosaj deleted the stephenarosaj/handle-executeQuery-refType-mismatch branch October 15, 2024 21:49
@google-oss-bot google-oss-bot mentioned this pull request Oct 17, 2024
@firebase firebase locked and limited conversation to collaborators Nov 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants