CRUD filter break certain cache updates #1617

Closed
opened 2026-05-10 15:46:56 +02:00 by leuckeju · 3 comments
Member

CRDUProvider:

  function updateFilters() {
    // queryVariables should be deeply reactive and this should work in all cases
    crud.queryVariables.value.filters = JSON.stringify({
      ...activeFilters.value,
      ...(objectSchema.value.enableServerSearch && searchString.value
        ? { search: searchString.value }
        : {}),
    });
    crud.queryRefetch(crud.queryVariables.value);
  }

should be

are not, however, if one would override them like this:

  <c-r-u-d-provider
    :object-schema="{
      type: 'GroupMembershipType',
    :query-variables="{ id: props.group.id }"
  />

This results in the cache read in the updateAfterMutate to fail with

    // Sometimes queryData is null, e.g. if using other query variables
    if (queryData === null) {
      console.warn("[useCrud] cached query data in updateCache is null.");
      console.debug("fullQuery", fullQuery);
      console.log(cache.extract());
      return;
    }

The problem seems to be, that while the filters are present while querying (and thus in the cache-set-key), they are not reactively included in the variables, when building the cache-get-key.

I am not quite sure how to fix this (esp. non-breakingly), but a quick (while dirty) fix would be to insert empty filters in the queryVariables prop like this:

  <c-r-u-d-provider
    :object-schema="{
      type: 'GroupMembershipType',
    :query-variables="{ id: props.group.id, filters: '{}' }"
  />
CRDUProvider: ```js function updateFilters() { // queryVariables should be deeply reactive and this should work in all cases crud.queryVariables.value.filters = JSON.stringify({ ...activeFilters.value, ...(objectSchema.value.enableServerSearch && searchString.value ? { search: searchString.value } : {}), }); crud.queryRefetch(crud.queryVariables.value); } ``` > should be are not, however, if one would override them like this: ```html <c-r-u-d-provider :object-schema="{ type: 'GroupMembershipType', :query-variables="{ id: props.group.id }" /> ``` This results in the cache read in the updateAfterMutate to fail with ```js // Sometimes queryData is null, e.g. if using other query variables if (queryData === null) { console.warn("[useCrud] cached query data in updateCache is null."); console.debug("fullQuery", fullQuery); console.log(cache.extract()); return; } ``` The problem seems to be, that while the filters are present while querying (and thus in the cache-set-key), they are not reactively included in the variables, when building the cache-get-key. I am not quite sure how to fix this (esp. non-breakingly), but a quick (while dirty) fix would be to insert empty `filters` in the `queryVariables` prop like this: ```html <c-r-u-d-provider :object-schema="{ type: 'GroupMembershipType', :query-variables="{ id: props.group.id, filters: '{}' }" /> ```
Owner

assigned to @leuckeju

assigned to @leuckeju
Author
Member

mentioned in merge request !3947

mentioned in merge request !3947
Owner

mentioned in commit 90b40e3a4d

mentioned in commit 90b40e3a4d9f2f2b40b1ab2d4c7fc5d494a36fd2
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
aleksis/AlekSIS-Core#1617
No description provided.