Skip to content

Conversation

@LucasLefevre
Copy link
Contributor

Let's say we trigger two times a RPC that fails.

The first time, the cache is empty and we make the RPC. The ram cache is filled with prom.

The second time, we get prom from the ram cache.

When the RPC actually finishes, we end up in

.catch((error) => {
    this.ramCache.delete(table, key);
    def.reject(error);
});

=> the RPC failure is catched, which means prom itself is not rejected. Instead, it resolves with the result of .catch(...), which is undefined

Here is a simplified toy example:

const prom = Promise.resolve(
    Promise.reject(new Error("fetch failed")).catch(() => {})
);

In this example, prom is successful and the result is undefined

"

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Nov 28, 2025

Pull request status dashboard

@C3POdoo C3POdoo requested review from a team, BastienFafchamps and kebeclibre and removed request for a team November 28, 2025 15:34
@LucasLefevre LucasLefevre force-pushed the saas-18.3-rejected-persistent-cache-lul branch 3 times, most recently from ed9003e to 58fe3ad Compare November 28, 2025 17:42
Copy link
Contributor

@aab-odoo aab-odoo left a comment

Choose a reason for hiding this comment

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

Good catch. As of 19 I think it's fine because we reworked the function (which is more complicated as of 18.4). See #233610

fallback()
.then((result) => {
this.indexedDB.write(table, key, result);
this.ramCache.write(table, key, result);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this necessary as we already have def that resolves with result in the ram cache? If this is necessary somehow, I think you should write Promise.resolve(result) in the cache, s.t. further calls receive a promise as expected (line 44)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is necessary when the value is retrieved first from indexedDB (which resolves def), but then the fallback returns another value: ramCache needs to be updated with the newer value. (it is covered by a test).

I adapted the code with Promise.resolve(result)

As of 19 I think it's fine because we reworked the function (which is more complicated as of 18.4)

👍 I'll just leave the test in the fw-port then

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it is necessary when the value is retrieved first from indexedDB (which resolves def), but then the fallback returns another value: ramCache needs to be updated with the newer value. (it is covered by a test).

Of course

Let's say we trigger two times a RPC that fails.

The first time, the cache is empty and we make the RPC. The ram cache is
filled with `prom`.

The second time, we get `prom` from the ram cache.

When the RPC actually finishes, we end up in
```
.catch((error) => {
    this.ramCache.delete(table, key);
    def.reject(error);
});
```

=> the RPC failure is catched, which means `prom` itself is not rejected.
Instead, it resolves with the result of `.catch(...)`, which is `undefined`

Here is a simplified toy example:

```
const prom = Promise.resolve(
    Promise.reject(new Error("fetch failed")).catch(() => {})
);
```
In this example, `prom` is successful and the result is `undefined`

Co-authored-by: rrahir <rar@odoo.com>
@LucasLefevre LucasLefevre force-pushed the saas-18.3-rejected-persistent-cache-lul branch from 58fe3ad to 05d2a5b Compare December 1, 2025 11:38
Copy link
Contributor

@aab-odoo aab-odoo left a comment

Choose a reason for hiding this comment

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

robodoo r+

robodoo pushed a commit that referenced this pull request Dec 1, 2025
Let's say we trigger two times a RPC that fails.

The first time, the cache is empty and we make the RPC. The ram cache is
filled with `prom`.

The second time, we get `prom` from the ram cache.

When the RPC actually finishes, we end up in
```
.catch((error) => {
    this.ramCache.delete(table, key);
    def.reject(error);
});
```

=> the RPC failure is catched, which means `prom` itself is not rejected.
Instead, it resolves with the result of `.catch(...)`, which is `undefined`

Here is a simplified toy example:

```
const prom = Promise.resolve(
    Promise.reject(new Error("fetch failed")).catch(() => {})
);
```
In this example, `prom` is successful and the result is `undefined`

closes #237984

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Co-authored-by: rrahir <rar@odoo.com>
@robodoo robodoo closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants