ChristopheCVB / strapi-plugin-soft-delete

Powerful Strapi based Soft Delete feature, never loose content again
MIT License
15 stars 4 forks source link

_softDeletedAt filter do not spread for nested records #8

Open SvaRgoS opened 10 months ago

SvaRgoS commented 10 months ago

Bug report

Required System information

Describe the bug

I run the following query


query Suppliers($filters: SupplierFiltersInput, $certificationsFilters2: CertificationFiltersInput) {
  suppliers(filters: $filters) {
    data {
      id
      attributes {
        companyName
        recipient_organization {
          data {
            id
            attributes {
              name
              certifications(filters: $certificationsFilters2) {
                data {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

some of the Suppliers have a recipient_organization that have a few deleted certifications

And they appear in the results. Unfortunately.

I guess because


const sdWrapParams = async (defaultService: any, opts: any, ctx: { uid: string, action: string }) => {
  const { uid, action } = ctx;
  const wrappedParams = await defaultService.wrapParams(opts, ctx);

  if (!plugin.supportsContentType(uid)) {
    return wrappedParams;
  }

  // Prevent users to set values for _softDeletedAt, _softDeletedById, and _softDeletedByType
  if (wrappedParams.data) {
    delete wrappedParams.data._softDeletedAt;
    delete wrappedParams.data._softDeletedById;
    delete wrappedParams.data._softDeletedByType;
  }

  return {
    ...wrappedParams,
    filters: {
      $and: [
        {
          ...wrappedParams.filters
        },
        {
          _softDeletedAt: {
            $null: true
          },
        },
      ],
    },
  };
}

the following filter

     _softDeletedAt: {
            $null: true
          },

apply only for top level entity.

Steps to reproduce the behavior

  1. Create two or more entities
  2. add relations between they
  3. add records to both of the table
  4. remove some of nested records
  5. Make request with related nested records.

You will see deleted records in the result

Expected behavior

I think would be good to get only non-deleted records.

cdreier commented 8 months ago

we just stumpled across the same issue, did you find a good solution or workaround in the meantime? when trying to set _softDeletedAt in the query filter, it fails the gql validations

edit: same problem in the strapi ui, you still see all the soft-deleted entities in the linked fields

SvaRgoS commented 8 months ago

No, I don't have a solution at the moment :-( I'm going to remove the plugin from the project. That would be nice, but I don't need it right now.

iantrudell commented 5 months ago

Has anyone found a workaround or solution for this? We are unable to use this currently because we have so many populated relations that keep returning related collection entries that were soft deleted.

Example: Collection: Category Collection: Post

Category has many Posts

Delete a post (soft delete)

Get Category, populate all posts in that category - the populate still returns the soft deleted posts