nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: luin/ioredis
Pull request #410 (2016-12-14 10:34:06)

Quit immediately when reconnecting
I'm not sure if this is the right approach but the idea is to be able to quit immediately when `redis.quit()` is called and the client is in the reconnecting state. In this case, `quit()` should not have to wait for the connection to be ready.

What do you think?

ruimarinho: @luin do you have time for some feedback here?
luin: Sorry for the late response. There's a problem that the `QUIT` command returns an `OK` so the `command.resolve()` should reflect it.
ruimarinho: No problem, I appreciate your time! Is that a simple `OK` or `[null, OK]`? From the Redis specification it looks like it's a Simple String Response. I've updated the PR to reply with an `OK` for now.
luin: I think `command.resolve('OK')` should be `command.resolve(new Buffer('OK'))` to handle the case that users call `redis.quitBuffer()`.

We'd better also include a test for it:

```
redis.quitBuffer().then(function (result) {
    expect(result).to.be.instanceof(Buffer);
    expect(result.toString()).to.eql('OK');
})
```
ruimarinho: SGTM! Do you think this should be a separate test?
luin: Yes I think it should be a separate test since `quit` & `quitBuffer` are two different commands.
ruimarinho: Let me know if you like the style of the new test.
luin: LGTM! 👍 

Patch:
diff --git a/lib/redis.js b/lib/redis.js
index 47be4c8..513c0f4 100644
--- a/lib/redis.js
+++ b/lib/redis.js
@@ -579,6 +579,12 @@ Redis.prototype.sendCommand = function (command, stream) {
     return command.promise;
   }
 
+  if (!writable && command.name === 'quit' && this.offlineQueue.length === 0) {
+    this.disconnect();
+    command.resolve(new Buffer('OK'));
+    return command.promise;
+  }
+
   if (writable) {
     debug('write command[%d] -> %s(%s)', this.condition.select, command.name, command.args);
     (stream || this.stream).write(command.toWritable());


Test patch:
diff --git a/test/functional/connection.js b/test/functional/connection.js
index ba3079c..9301d77 100644
--- a/test/functional/connection.js
+++ b/test/functional/connection.js
@@ -146,6 +146,38 @@ describe('connection', function () {
         }
       });
     });
+
+    it('should skip reconnecting if quitting before connecting', function (done) {
+      var count = 0;
+      var redis = new Redis({
+        port: 8999,
+        retryStrategy: function () {
+          count++;
+        }
+      });
+
+      redis.quit().then(function (result) {
+        expect(result).to.eql('OK');
+        expect(count).to.eql(0);
+        done();
+      });
+    });
+
+    it('should skip reconnecting if quitting before connecting (buffer)', function (done) {
+      var count = 0;
+      var redis = new Redis({
+        port: 8999,
+        retryStrategy: function () {
+          count++;
+        }
+      });
+
+      redis.quitBuffer().then(function (result) {
+        expect(result).to.be.instanceof(Buffer);
+        expect(result.toString()).to.eql('OK');
+        done();
+      });
+    });
   });
 
   describe('connectionName', function () {
Repository: tannerlinsley/react-query
Pull request #166 (2020-02-27 20:13:28)

Update useMutation memoization
This will fix the issue identified here https://github.com/tannerlinsley/react-query/issues/165, however I am not sure if the check on the status in the useCallback was needed for a particular reason?

This will allow the mutation function to safely be included in a dependency array of an effect, like below.
```javascript
const [mutate]  = useMutation(SOME_MUTATION);
React.useEffect(() => {
  mutate();
}, [mutate]);
```

tannerlinsley: That multiline suggesting thing is trippy!
owinter86: Yeah that works too.
tannerlinsley: Yeah, the check is to make sure the mutation is idle or an existing mutation is settled before allowing another one to to be triggered. We may not need it, but I'd like to keep it in until a use case comes along to remove it.

Patch:
diff --git a/src/queryCache.js b/src/queryCache.js
index af298ae7b..da4ed8185 100644
--- a/src/queryCache.js
+++ b/src/queryCache.js
@@ -306,7 +306,7 @@ export function makeQueryCache() {
           })
         }
 
-        // throw error
+        throw error
       }
     }
 
@@ -381,7 +381,7 @@ export function makeQueryCache() {
                   instance.onSettled && instance.onSettled(undefined, error)
               )
 
-              throw error
+              // throw error
             }
           }
         })()
diff --git a/src/useMutation.js b/src/useMutation.js
index 3d9f183d4..986ec8f3c 100644
--- a/src/useMutation.js
+++ b/src/useMutation.js
@@ -64,12 +64,15 @@ export function useMutation(
     ...useConfigContext(),
     ...config,
   })
+  
+  const getStatus = useGetLatest(state.status)
 
   const mutate = React.useCallback(
     async (variables, options = {}) => {
-      if (![statusIdle, statusSuccess, statusError].includes(state.status)) {
+      if (![statusIdle, statusSuccess, statusError].includes(getStatus())) {
         return
       }
+      
       dispatch({ type: actionMutate })
 
       const resolvedOptions = {
@@ -95,7 +98,7 @@ export function useMutation(
         }
       }
     },
-    [getConfig, getMutationFn, state.status]
+    [getConfig, getMutationFn, getStatus]
   )
 
   const reset = React.useCallback(() => dispatch({ type: actionReset }), [])


Test patch:
diff --git a/src/tests/useQuery.test.js b/src/tests/useQuery.test.js
index 64fdaa229..1358fae12 100644
--- a/src/tests/useQuery.test.js
+++ b/src/tests/useQuery.test.js
@@ -157,4 +157,26 @@ describe('useQuery', () => {
     await waitForElement(() => rendered.getByText('default'))
     expect(queryFn).not.toHaveBeenCalled()
   })
+
+  it('should set status to error if queryFn throws', async () => {
+    function Page() {
+      const { status } = useQuery(
+        'test',
+        () => {
+          return Promise.reject('Error test')
+        },
+        { retry: false },
+      )
+
+      return (
+        <div>
+          <h1>{status}</h1>
+        </div>
+      )
+    }
+
+    const rendered = render(<Page />)
+
+    await waitForElement(() => rendered.getByText('error'))
+  })
 })
Repository: tannerlinsley/react-query
Pull request #167 (2020-02-27 20:28:13)

Fix query state being set to "success" when query function throw
Bug reproduction: https://codesandbox.io/s/musing-framework-jvo0s


Patch:
diff --git a/src/queryCache.js b/src/queryCache.js
index af298ae7b..da4ed8185 100644
--- a/src/queryCache.js
+++ b/src/queryCache.js
@@ -306,7 +306,7 @@ export function makeQueryCache() {
           })
         }
 
-        // throw error
+        throw error
       }
     }
 
@@ -381,7 +381,7 @@ export function makeQueryCache() {
                   instance.onSettled && instance.onSettled(undefined, error)
               )
 
-              throw error
+              // throw error
             }
           }
         })()


Test patch:
diff --git a/src/tests/useQuery.test.js b/src/tests/useQuery.test.js
index 64fdaa229..1358fae12 100644
--- a/src/tests/useQuery.test.js
+++ b/src/tests/useQuery.test.js
@@ -157,4 +157,26 @@ describe('useQuery', () => {
     await waitForElement(() => rendered.getByText('default'))
     expect(queryFn).not.toHaveBeenCalled()
   })
+
+  it('should set status to error if queryFn throws', async () => {
+    function Page() {
+      const { status } = useQuery(
+        'test',
+        () => {
+          return Promise.reject('Error test')
+        },
+        { retry: false },
+      )
+
+      return (
+        <div>
+          <h1>{status}</h1>
+        </div>
+      )
+    }
+
+    const rendered = render(<Page />)
+
+    await waitForElement(() => rendered.getByText('error'))
+  })
 })
Repository: tannerlinsley/react-query
Pull request #643 (2020-06-27 05:45:03)

fix disabling query in suspense mode
#642 

tannerlinsley: Bingo da dingo! This is great.

Patch:
diff --git a/src/react/utils.js b/src/react/utils.js
index 0d18852ba..6d62d75d7 100644
--- a/src/react/utils.js
+++ b/src/react/utils.js
@@ -68,7 +68,11 @@ export function handleSuspense(queryInfo) {
       throw queryInfo.error
     }
 
-    if (queryInfo.query.config.suspense && queryInfo.status !== statusSuccess) {
+    if (
+      queryInfo.query.config.suspense &&
+      queryInfo.status !== statusSuccess &&
+      queryInfo.query.config.enabled
+    ) {
       queryInfo.query.wasSuspended = true
       throw queryInfo.query.fetch()
     }


Test patch:
diff --git a/src/react/tests/suspense.test.js b/src/react/tests/suspense.test.js
index 81d405ad4..e30de2605 100644
--- a/src/react/tests/suspense.test.js
+++ b/src/react/tests/suspense.test.js
@@ -151,4 +151,29 @@ describe("useQuery's in Suspense mode", () => {
 
     await waitFor(() => rendered.getByText('rendered'))
   })
+
+  it('should not call the queryFn when not enabled', async () => {
+    const queryFn = jest.fn()
+    queryFn.mockImplementation(() => sleep(10))
+
+    function Page() {
+      const [enabled, setEnabled] = React.useState(false)
+      useQuery(['test'], queryFn, { suspense: true, enabled })
+
+      return <button aria-label="fire" onClick={() => setEnabled(true)} />
+    }
+
+    const rendered = render(
+      <React.Suspense fallback="loading">
+        <Page />
+      </React.Suspense>
+    )
+
+    expect(queryFn).toHaveBeenCalledTimes(0)
+
+    fireEvent.click(rendered.getByLabelText('fire'))
+
+    expect(queryFn).toHaveBeenCalledTimes(1)
+    await waitFor(() => rendered.getByLabelText('fire'))
+  })
 })
Repository: tannerlinsley/react-query
Pull request #645 (2020-06-27 21:55:18)

fix(setQueryData) unresolved promises
setQueryData(notInstantiatedQueryKey) now assigns Promise.resolve() instead of new Promise(noop) that caused a never ending promise en certain scenarios. Ref bug #639

EDIT
Forgot to mention that I went with `Promise.resolve` because in some other place we do `const promise = fn(...)` and if we simply make `fn` a `noop` then `promise` will be undefined and when we later do `promise.cancel` it will break. (typescript would help us in this case)

Here is where we access `promise.cancel` https://github.com/tannerlinsley/react-query/blob/1.x/src/queryCache.js#L375


Patch:
diff --git a/src/queryCache.js b/src/queryCache.js
index 47902339d..dfbce4f21 100644
--- a/src/queryCache.js
+++ b/src/queryCache.js
@@ -236,7 +236,7 @@ export function makeQueryCache() {
 
     if (!queries.length && typeof queryKey !== 'function') {
       queries = [
-        cache._buildQuery(queryKey, undefined, () => new Promise(noop), {
+        cache._buildQuery(queryKey, undefined, () => Promise.resolve(), {
           ...defaultConfigRef.current,
           ...config,
         }),


Test patch:
diff --git a/src/tests/queryCache.test.js b/src/tests/queryCache.test.js
index 81b9de323..51a15256b 100644
--- a/src/tests/queryCache.test.js
+++ b/src/tests/queryCache.test.js
@@ -192,4 +192,15 @@ describe('queryCache', () => {
     expect(newQuery.state.markedForGarbageCollection).toBe(false)
     expect(newQuery.state.data).toBe('data')
   })
+
+  // this covers bug https://github.com/tannerlinsley/react-query/issues/639
+  test('setQueryData of not instatiated query uses a resolved promise as queryFn', async () => {
+    let promiseIsResolved = false
+    const queryCache = makeQueryCache()
+    const queryKey = 'notInstantiated'
+    queryCache.setQueryData(queryKey, "data")
+    await queryCache.refetchQueries(queryKey, { force: true });
+    promiseIsResolved = true
+    expect(promiseIsResolved).toBe(true)
+  })
 })
Repository: tannerlinsley/react-query
Pull request #944 (2020-08-31 19:27:50)

fix: make sure initial data is used when switching queries
Fixes https://github.com/tannerlinsley/react-query/issues/927

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.



Patch:
diff --git a/package.json b/package.json
index d80fb026c..93825fa3a 100644
--- a/package.json
+++ b/package.json
@@ -41,7 +41,8 @@
   "files": [
     "dist",
     "types",
-    "scripts"
+    "scripts",
+    "hydration.js"
   ],
   "dependencies": {},
   "peerDependencies": {
diff --git a/src/core/queryObserver.ts b/src/core/queryObserver.ts
index 505308ed0..1180c27a1 100644
--- a/src/core/queryObserver.ts
+++ b/src/core/queryObserver.ts
@@ -277,9 +277,10 @@ export class QueryObserver<TResult, TError> {
 
     // Remove the initial data when there is an existing query
     // because this data should not be used for a new query
-    const config = prevQuery
-      ? { ...this.config, initialData: undefined }
-      : this.config
+    const config =
+      this.config.keepPreviousData && prevQuery
+        ? { ...this.config, initialData: undefined }
+        : this.config
 
     const newQuery = config.queryCache!.buildQuery(config.queryKey, config)
 


Test patch:
diff --git a/src/react/tests/useQuery.test.tsx b/src/react/tests/useQuery.test.tsx
index 2307b4efe..e30206c76 100644
--- a/src/react/tests/useQuery.test.tsx
+++ b/src/react/tests/useQuery.test.tsx
@@ -698,6 +698,38 @@ describe('useQuery', () => {
     consoleMock.mockRestore()
   })
 
+  it('should keep initial stale and initial data when the query key changes', async () => {
+    const key = queryKey()
+    const states: QueryResult<{ count: number }>[] = []
+
+    function Page() {
+      const [count, setCount] = React.useState(0)
+      const state = useQuery([key, count], () => ({ count: 10 }), {
+        initialStale: () => false,
+        initialData: () => ({ count }),
+      })
+      states.push(state)
+
+      React.useEffect(() => {
+        setTimeout(() => setCount(1))
+      }, [])
+
+      return null
+    }
+
+    render(<Page />)
+
+    await waitFor(() => expect(states.length).toBe(5))
+
+    expect(states).toMatchObject([
+      { data: { count: 0 } },
+      { data: { count: 0 } },
+      { data: { count: 1 } },
+      { data: { count: 1 } },
+      { data: { count: 10 } },
+    ])
+  })
+
   it('should retry specified number of times', async () => {
     const key = queryKey()
     const consoleMock = mockConsoleError()
Repository: tannerlinsley/react-query
Pull request #1403 (2020-12-14 15:32:13)

fix(queryCache): stop deepIncludes exception comparing null
typeof null === 'object'

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/tannerlinsley/react-query/jezxjcdfb](https://vercel.com/tannerlinsley/react-query/jezxjcdfb)  
✅ Preview: *In Progress*



Patch:
diff --git a/src/core/utils.ts b/src/core/utils.ts
index dffaf2655..3eb8eab3c 100644
--- a/src/core/utils.ts
+++ b/src/core/utils.ts
@@ -241,7 +241,7 @@ export function partialDeepEqual(a: any, b: any): boolean {
     return false
   }
 
-  if (typeof a === 'object' && typeof b === 'object') {
+  if (a && b && typeof a === 'object' && typeof b === 'object') {
     return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]))
   }
 


Test patch:
diff --git a/src/core/tests/utils.test.tsx b/src/core/tests/utils.test.tsx
index cac97f261..9f1f5411b 100644
--- a/src/core/tests/utils.test.tsx
+++ b/src/core/tests/utils.test.tsx
@@ -68,6 +68,30 @@ describe('core/utils', () => {
       const b = [1, 2]
       expect(partialDeepEqual(a, b)).toEqual(true)
     })
+
+    it('should return `false` if a is null and b is not', () => {
+      const a = null
+      const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
+      expect(partialDeepEqual(a, b)).toEqual(false)
+    })
+
+    it('should return `false` if a contains null and b is not', () => {
+      const a = { a: null, c: 'c', d: [] }
+      const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
+      expect(partialDeepEqual(a, b)).toEqual(false)
+    })
+
+    it('should return `false` if b is null and a is not', () => {
+      const a = { a: { b: 'b' }, c: 'c', d: [] }
+      const b = null
+      expect(partialDeepEqual(a, b)).toEqual(false)
+    })
+
+    it('should return `false` if b contains null and a is not', () => {
+      const a = { a: { b: 'b' }, c: 'c', d: [] }
+      const b = { a: null, c: 'c', d: [{ d: 'd ' }] }
+      expect(partialDeepEqual(a, b)).toEqual(false)
+    })
   })
 
   describe('replaceEqualDeep', () => {
Repository: tannerlinsley/react-query
Pull request #1740 (2021-02-04 09:14:16)

fix: accept null values in mutate function
Fixes https://github.com/tannerlinsley/react-query/issues/1632

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/tannerlinsley/react-query/r8nof9pke](https://vercel.com/tannerlinsley/react-query/r8nof9pke)  
✅ Preview: *In Progress*



Patch:
diff --git a/src/core/mutationObserver.ts b/src/core/mutationObserver.ts
index 05476efda..da52a321c 100644
--- a/src/core/mutationObserver.ts
+++ b/src/core/mutationObserver.ts
@@ -116,7 +116,8 @@ export class MutationObserver<
 
     this.currentMutation = this.client.getMutationCache().build(this.client, {
       ...this.options,
-      variables: variables ?? this.options.variables,
+      variables:
+        typeof variables !== 'undefined' ? variables : this.options.variables,
     })
 
     this.currentMutation.addObserver(this)


Test patch:
diff --git a/src/core/tests/mutations.test.tsx b/src/core/tests/mutations.test.tsx
index 30264f895..45dcdd547 100644
--- a/src/core/tests/mutations.test.tsx
+++ b/src/core/tests/mutations.test.tsx
@@ -24,6 +24,23 @@ describe('mutations', () => {
     expect(result).toBe(result)
   })
 
+  test('mutate should accept null values', async () => {
+    let variables
+
+    const mutation = new MutationObserver(queryClient, {
+      mutationFn: async (vars: unknown) => {
+        variables = vars
+        return vars
+      },
+    })
+
+    mutation.mutate(null)
+
+    await sleep(10)
+
+    expect(variables).toBe(null)
+  })
+
   test('setMutationDefaults should be able to set defaults', async () => {
     const key = queryKey()
Repository: microsoft/ApplicationInsights-node.js
Pull request #570 (2019-11-22 18:42:03)

Include port name in "target" for dependency telemetry


Patch:
diff --git a/AutoCollection/HttpDependencyParser.ts b/AutoCollection/HttpDependencyParser.ts
index 692fc89..3a7ef22 100644
--- a/AutoCollection/HttpDependencyParser.ts
+++ b/AutoCollection/HttpDependencyParser.ts
@@ -64,6 +64,10 @@ class HttpDependencyParser extends RequestParser {
             remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_HTTP;
         }
 
+        if (urlObject.port) {
+            remoteDependencyTarget += ":" + urlObject.port;
+        }
+
         var dependencyTelemetry: Contracts.DependencyTelemetry & Contracts.Identified = {
             id: dependencyId,
             name: dependencyName,


Test patch:
diff --git a/Tests/AutoCollection/HttpDependencyParser.tests.ts b/Tests/AutoCollection/HttpDependencyParser.tests.ts
index a513816..625eb71 100644
--- a/Tests/AutoCollection/HttpDependencyParser.tests.ts
+++ b/Tests/AutoCollection/HttpDependencyParser.tests.ts
@@ -61,7 +61,7 @@ describe("AutoCollection/HttpDependencyParser", () => {
             assert.equal(dependencyTelemetry.success, true);
             assert.equal(dependencyTelemetry.name, "POST /search");
             assert.equal(dependencyTelemetry.data, "http://bing.com:8000/search?q=test");
-            assert.equal(dependencyTelemetry.target, "bing.com");
+            assert.equal(dependencyTelemetry.target, "bing.com:8000");
         });
 
         it("should return correct data for a request options object", () => {
Repository: microsoft/ApplicationInsights-node.js
Pull request #674 (2020-09-02 23:18:53)

rdd: set target port before target correlation id
Fixes an issue where `dependency.target` could look something like `example.com | cid-v1:abc:443`. The port component of the string, `:443`, should suffix `example.com`.

`example.com | cid-v1:abc:443` --> `example.com:443 | cid-v1:abc`


Patch:
diff --git a/AutoCollection/HttpDependencyParser.ts b/AutoCollection/HttpDependencyParser.ts
index 1450a26..f9db8b2 100644
--- a/AutoCollection/HttpDependencyParser.ts
+++ b/AutoCollection/HttpDependencyParser.ts
@@ -55,19 +55,20 @@ class HttpDependencyParser extends RequestParser {
         let remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_HTTP;
 
         let remoteDependencyTarget = urlObject.hostname;
+
+        if (urlObject.port) {
+            remoteDependencyTarget += ":" + urlObject.port;
+        }
+
         if (this.correlationId) {
             remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_AI;
             if (this.correlationId !== CorrelationIdManager.correlationIdPrefix) {
-                remoteDependencyTarget = urlObject.hostname + " | " + this.correlationId;
+                remoteDependencyTarget += " | " + this.correlationId;
             }
         } else {
             remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_HTTP;
         }
 
-        if (urlObject.port) {
-            remoteDependencyTarget += ":" + urlObject.port;
-        }
-
         var dependencyTelemetry: Contracts.DependencyTelemetry & Contracts.Identified = {
             id: dependencyId,
             name: dependencyName,


Test patch:
diff --git a/Tests/AutoCollection/HttpDependencyParser.tests.ts b/Tests/AutoCollection/HttpDependencyParser.tests.ts
index 671519b..7c02d48 100644
--- a/Tests/AutoCollection/HttpDependencyParser.tests.ts
+++ b/Tests/AutoCollection/HttpDependencyParser.tests.ts
@@ -29,6 +29,22 @@ describe("AutoCollection/HttpDependencyParser", () => {
             assert.equal(dependencyTelemetry.target, "bing.com");
         });
 
+        it("should return correct data for a URL string with correlationId", () => {
+            (<any>request)["method"] = "GET";
+            let parser = new HttpDependencyParser("http://bing.com:123/search", request);
+
+            response.statusCode = 200;
+            parser.onResponse(response);
+
+            parser["correlationId"] = "abcdefg";
+            let dependencyTelemetry = parser.getDependencyTelemetry();
+            assert.equal(dependencyTelemetry.dependencyTypeName, Contracts.RemoteDependencyDataConstants.TYPE_AI);
+            assert.equal(dependencyTelemetry.success, true);
+            assert.equal(dependencyTelemetry.name, "GET /search");
+            assert.equal(dependencyTelemetry.data, "http://bing.com:123/search");
+            assert.equal(dependencyTelemetry.target, "bing.com:123 | abcdefg");
+        });
+
         if (parseInt(process.versions.node.split(".")[0]) >= 10) {
             it("should return correct data for a URL instance", () => {
                 (<any>request)["method"] = "GET";