bito-code-review[bot] commented on PR #43583:
URL: https://github.com/apache/superset/pull/43583#issuecomment-5436561983
<!-- Bito Reply -->
The flagged issue is correct. The current implementation of the `useEffect`
hook in `DatasourceModal` fetches the ETag asynchronously, which allows the
user to potentially trigger a `PUT` request before `versionEtag` is populated.
This means the `If-Match` header would be missing, bypassing the optimistic
concurrency control.
To resolve this, you can disable the save button until the ETag is available
or the initial fetch completes. Here is a concise implementation to block
saving while the ETag is being fetched:
```tsx
// In DatasourceModal/index.tsx
const [isEtagLoading, setIsEtagLoading] = useState(false);
useEffect(() => {
if (etag || !show || !datasource.id) {
setVersionEtag(etag);
return;
}
setIsEtagLoading(true);
SupersetClient.get({ endpoint: `/api/v1/dataset/${datasource.id}` })
.then(({ response }) => {
setVersionEtag(response.headers.get('ETag') ?? undefined);
})
.finally(() => setIsEtagLoading(false));
}, [datasource.id, etag, show]);
// Then disable the save button:
// <Button disabled={isSaving || isEtagLoading} ... />
```
Would you like me to check the rest of the comments on this PR and implement
fixes for them as well?
**superset-frontend/src/components/Datasource/DatasourceModal/index.tsx**
```
const [isEtagLoading, setIsEtagLoading] = useState(false);
useEffect(() => {
if (etag || !show || !datasource.id) {
setVersionEtag(etag);
return;
}
setIsEtagLoading(true);
SupersetClient.get({ endpoint: `/api/v1/dataset/${datasource.id}` })
.then(({ response }) => {
setVersionEtag(response.headers.get('ETag') ?? undefined);
})
.finally(() => setIsEtagLoading(false));
}, [datasource.id, etag, show]);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]