Segments with sub-doc filters not working

This is a template you can use to report issues. You can also drag images, videos and include Preformatted text

Expected behavior

Filter on a sub document fields works when creating a segment

Actual behavior

Creating a segment like below gives error shown. Without the second condition saves properly

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version:
  • Express Version:
  • Sequelize Version:
  • Database Dialect:
  • Database Version:
  • Project Name:

Hi @Liam_Cheung,

Thank you for taking the time to report your issue.

I just tried to add a segment filtering by a sub document field and I worked well.
In order to help you out, I will need to know:

  • what error do you have in your browser console (in the Network tab, the failed job selected and previewed)
  • what version of forest-express-mongoose are you on?

Thanks.

Hi,

Thanks, we are on:
“forest-express-mongoose”: “^6.3.0”,

the details of the call that fail are:
PUT /api/segments/1979b7e0-c13b-11ea-89d0-f3bab00a480c HTTP/1.1
Host: api.forestadmin.com
Connection: keep-alive
Content-Length: 1461
Forest-Project-Id: 41780
Authorization: Bearer Forest-Rendering-Id: 60128
Content-Type: application/vnd.api+json
Accept: vnd.forestadmin-api+json; version=2.7.0
Forest-Environment-Id: 50945
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
Forest-Collection-Id: 2849914
Forest-Team-Id: 42021
Origin: https://app.forestadmin.com
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://app.forestadmin.com/Forest%20Map/EU%20Production/Operations/data/2849914/settings/segments
Accept-Encoding: gzip, deflate, br
Accept-Language:

{“data”:{“id”:“1979b7e0-c13b-11ea-89d0-f3bab00a480c”,“attributes”:{“name”:“Non Zero Accumulation Goals”,“type”:“manual”,“position”:0,“is_visible”:false,“default_sorting_field_order”:“descending”,“query”:null,“has_columns_configuration”:false},“relationships”:{“collection”:{“data”:{“type”:“collections”,“id”:“2849914”}},“filter”:{“data”:{“attributes”:{“type”:“and”},“relationships”:{“segment”:{“data”:{“type”:“segments”,“id”:“1979b7e0-c13b-11ea-89d0-f3bab00a480c”}},“conditions”:{“data”:[{“attributes”:{“embedded_field”:null,“operator”:“is”,“value”:“non_registered”,“belongs_to_segment”:false},“relationships”:{“filter”:{“data”:{“type”:“filters”,“id”:“195ce110-c13b-11ea-89d0-f3bab00a480c”}},“field”:{“data”:{“type”:“fields”,“id”:“834259e4-a85d-11ea-9e20-1971a04ca44c”}},“sub_field”:{“data”:null}},“type”:“conditions”,“id”:“19545590-c13b-11ea-89d0-f3bab00a480c”},{“attributes”:{“embedded_field”:{“id”:1,“field”:“confirmed”,“type”:“Number”,“enums”:{}},“operator”:“is not”,“value”:“0”,“belongs_to_segment”:false,“id”:“134985d2-a775-40e5-abad-ac985a3e25a4”},“relationships”:{“filter”:{“data”:{“type”:“filters”,“id”:“195ce110-c13b-11ea-89d0-f3bab00a480c”}},“field”:{“data”:{“type”:“fields”,“id”:“834259d2-a85d-11ea-9e20-1971a04ca44c”}}},“type”:“conditions”}]}},“type”:“filters”,“id”:“195ce110-c13b-11ea-89d0-f3bab00a480c”}},“default_sorting_field”:{“data”:{“type”:“fields”,“id”:“834280e0-a85d-11ea-9e20-1971a04ca44c”}},“columns”:{“data”:}},“type”:“segments”}}

HTTP/1.1 400 Bad Request
Server: Cowboy
Connection: keep-alive
X-Dns-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
Access-Control-Allow-Origin: https://app.forestadmin.com
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
Content-Length: 60
Etag: W/“3c-speXrJIeoykLjM9ink01HbZvv9o”
Date: Thu, 09 Jul 2020 13:31:01 GMT
Via: 1.1 vegur

{“errors”:[{“status”:400,“detail”:“Bad Request”,“meta”:{}}]}

@Liam_Cheung,

Thanks for sharing this.
We might have found an issue. I let you know about it.
In the meantime, can you please send me your model definition please?
I’m curious to know how you defined your amount in cents / confirmed.

Thanks.

const goalSchema = new Schema({
user_id: { type: Schema.Types.ObjectId, ref: ‘users’, required: true, index: true },
shortId: { type: String, unique: true },
sequence: { type: Number, default: 1 },
title: { type: String, required: true },
description: { type: String },
amountInCents: {
target: { type: Number, required: true, min: 100 },
confirmed: { type: Number, default: 0 },
committed: { type: Number, default: 0 },
},
);

Hi @Liam_Cheung,

We’ve spotted an issue that could be related to yours, but we are not able to reproduce the exact same behavior. We’ll work on a fix for a similar issue that should also fix what you are experiencing, and we’ll let you know once it is ready.

Thanks for reporting this!

Hi @Liam_Cheung,

We just released a fix on a very similar issue to the one you encountered.
Could you please try to create your segment again?

Thanks :pray:

Hi @anon34731316,

Still the same issue. I do notice some changes from your release that fixes other problems I was having, but not this one.

Liam

Hello @Liam_Cheung :wave:

I’ve picked up your model (I mocked the user model) and I successfully created a segment with the exact same configuration as yours.

Do you still encounter the issue ?

Regards,

Steve.

Hi Steve,

Take a look at this loom…still not working

Liam

Hi @Liam_Cheung,
We couldn’t reproduce your bug yet :exploding_head:
We spotted this issue though, in your payload there is a "enum": {} in your confirmed embedded field that doesn’t make any sense and makes it crash.

Did you define some enums for this model at some point?
Can you confirm that if you remove this segment, and make it again, the same problem occurs?

Thanks.

HI,

I tried the remove and start from scratch, and it did not work. Here is the video

While its possible there was a copy paste error at some point, I went through all the confirm fields and none of them have enums defined and in my .forestadmin-schema.json file the all have this pattern:

  "fields": [{
    "field": "confirm",
    "type": "Boolean",
    "defaultValue": null,
    "enums": null,
    "isRequired": true,
    "reference": null,
    "description": "Please confirm you wish to delete users recursively.",
    "position": 0,
    "widget": null
  }]

Hello @Liam_Cheung,

After a lot of digging, we were finally able to reproduce your issue. I’m opening a bug report on our side.

We’ll keep you posted once it is fixed & available.

Thanks for your help :pray:

2 Likes

Hi @Liam_Cheung thank you for your patience.

It has been fixed thanks to @jeffladiray (see this PR) and released in forest-express mongoose 6.3.3 :tada:. Update to the latest version (6.3.6 as of today), restart your backend and it should then fix your issue.

Let us know if you still have a problem.