Calling this.sanitizeOutput in custom controller is removing populated relation (user)

async findBySlug(ctx) {
      const { slug } = ctx.params;

      const letter = await strapi.documents("api::letter.letter").findFirst({
        filters: {
          slug: {
            $eq: slug,
          },
        },
        populate: ["user"],
      });

      console.log("letter with user: ", letter);

      if (!letter) {
        return ctx.notFound();
      }

      const sanitizedLetter = await this.sanitizeOutput(letter, ctx);

      console.log("user removed: ", sanitizedLetter);
      return this.transformResponse(sanitizedLetter);
    },

This topic has been created from a Discord post (1264304820148244501) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Has anyone else noticed issues with sanitizeOutput removing relations? I’ve checked my permissions and both public & authenticated roles have access to find or findOne user, upload, etc.

i see the relation on the generated contentTypes.d.ts

  collectionName: 'letters';
  info: {
    singularName: 'letter';
    pluralName: 'letters';
    displayName: 'Letter';
    description: '';
  };
  options: {
    draftAndPublish: false;
  };
  attributes: {
    title: Schema.Attribute.String &
      Schema.Attribute.Required &
      Schema.Attribute.DefaultTo<'title'>;
    slug: Schema.Attribute.UID<'title'>;
    old_slug: Schema.Attribute.String;
    content: Schema.Attribute.JSON;
    old_content: Schema.Attribute.JSON;
    old_status: Schema.Attribute.String;
    date_created: Schema.Attribute.DateTime;
    date_updated: Schema.Attribute.DateTime;
    reactions: Schema.Attribute.JSON;
    allow_reactions: Schema.Attribute.Boolean &
      Schema.Attribute.Required &
      Schema.Attribute.DefaultTo<true>;
    user: Schema.Attribute.Relation<
      'manyToOne',
      'plugin::users-permissions.user'
    >;
    is_published: Schema.Attribute.Boolean &
      Schema.Attribute.Required &
      Schema.Attribute.DefaultTo<false>;
    createdAt: Schema.Attribute.DateTime;
    updatedAt: Schema.Attribute.DateTime;
    publishedAt: Schema.Attribute.DateTime;
    createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
      Schema.Attribute.Private;
    updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
      Schema.Attribute.Private;
    locale: Schema.Attribute.String;
  };
}