pentacent / keila

Open Source Newsletter Tool.

Home Page:https://keila.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Viewing segments created by API fails

dompie opened this issue · comments

I have created a Segment using the API that returned the following Response:

status code: 200
body content: "{"data":{"id":"nsgm_X4V8agWa","name":"Members 140700","filter":{"contactType":"member"}}}"

//another request
status code: 200
body content: ^ "{"data":{"id":"nsgm_9qrNeLZX","name":"Members 140717","filter":{"data":{"contactType":"member"}}}}"

//another request
status code: 200
body content: "{"data":{"id":"nsgm_Xar2Xg4x","name":"Members 141736","filter":{"data.contactType":{"$in":"member"}}}}"

When I try to edit the segment in UI, an internal server error occours. The server log from docker is as follows:

keila-1     | 12:27:55.889 request_id=F8J2S7U8vSkjQmoAAAqh [info] GET /projects/np_weLJnLY5/segments/nsgm_Mvg6DrZD
keila-1     | 12:27:55.927 request_id=F8J2S7U8vSkjQmoAAAqh [info] Sent 500 in 38ms
keila-1     | 12:27:55.928 [error] #PID<0.3114.0> running KeilaWeb.Endpoint (connection #PID<0.3109.0>, stream id 3) terminated
keila-1     | Server: keila.local:4000 (http)
keila-1     | Request: GET /projects/np_weLJnLY5/segments/nsgm_Mvg6DrZD
keila-1     | ** (exit) an exception was raised:
keila-1     |     ** (RuntimeError) Unsupported filter "contactType": ""member""
keila-1     |         (keila 0.14.0) lib/keila/contacts/query.ex:145: Keila.Contacts.Query.build_condition/2
keila-1     |         (stdlib 5.2) maps.erl:416: :maps.fold_1/4
keila-1     |         (keila 0.14.0) lib/keila/contacts/query.ex:74: Keila.Contacts.Query.filter/2
keila-1     |         (keila 0.14.0) lib/keila/contacts/query.ex:46: Keila.Contacts.Query.apply/2
keila-1     |         (keila 0.14.0) lib/keila/contacts/contacts.ex:74: Keila.Contacts.get_project_contacts/2
keila-1     |         (keila 0.14.0) lib/keila_web/live/segment_edit_live.ex:170: KeilaWeb.SegmentEditLive.put_contacts/1
keila-1     |         (keila 0.14.0) lib/keila_web/live/segment_edit_live.ex:160: KeilaWeb.SegmentEditLive.update_assigns/1
keila-1     |         (keila 0.14.0) lib/keila_web/live/segment_edit_live.ex:51: KeilaWeb.SegmentEditLive.mount/3

Expected behaviour:

  1. The created segment should be editable and deletable.
  2. and the API should prevent creating invalid segments.

Only the third filter is a valid filter:

{"data.contactType":{"$in":"member"}}

Using the contact property without the data. prefix or nested under a "data" key is not supported.

{"data.contactType":{"$in":"Member"}}

does not work either. $in expects an array like this:

{"data.contactType":{"$in":["Member"]}}

Thanks you @wmnnd 👍

FYI: segments with invalid filters will stay undeletable in the UI as a white page with "Internal server error" is displayed when trying to edit such a segment.