# Dot-notation query through multi-entity field

**URL:** <https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132>\
**Category:** Flow Production Tracking\
**Tags:** api, python-api\
**Created:** [September 21, 2020, 3:38pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132 "2020-09-21T15:38:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [September 21, 2020, 3:38pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/1 "2020-09-21T15:38:18Z")

</div>

Hi,

Yesterday some artists started noticing that certain code wasn’t working anymore. In a very simplified way, it looks like this:

```python
for element in sg.find('Element',
        [['shots.Shot.sg_episode.CustomEntity01.code', 'is', 'ep01']],
        ['shots.Shot.sg_status_list']):
    print element['shots.Shot.sg_status_list']

```

Unsurprisingly for me, it raises a `KeyError`. I didn’t write this tool— I’ve always thought querying through a multi-entity field using dot notation never works because the relationship isn’t 1:1 (i.e. an Element could be linked to more than one Shot), **but the artists insist that this was working earlier this month.**

I’ve tested it with Python API versions 3.0.32 (which we were using in March) and 3.0.37 (which we’re using now)— no dice. Is it possible that an update to Shotgun itself has altered this behaviour?

Thanks in advance,  
Unai

---

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [September 21, 2020, 4:28pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/2 "2020-09-21T16:28:55Z")

</div>

Okay this is a bit absurd now. Further down the code, there’s this gem:

```python
    shot_code = element['shots.Shot.sg_status_list'][0]['name']

```

Which makes me think that, maybe, when you asked SG for `multi_entity_field.Entity.field` before, it would give you the same result as querying `multi_entity_field` alone, but now it simply ignores it? Is this possible?

---

<div class="post-metadata">

**Author:** ![brandon.foster](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/brandon.foster/32/91_2.png) [@brandon.foster](https://community.shotgridsoftware.com/u/brandon.foster)\
**Post date:** [September 21, 2020, 5:44pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/3 "2020-09-21T17:44:55Z")

</div>

Hi Unai,

In the 8.17 release we began more strictly enforcing the way bubbled fields (dot notation) data is accessed. In your example, do the artists running the code have the permission to see each entity and field contents along the entire chain (i.e. can they see `sg_episode` , `CustomEntity01`'s, and the `code` field on those entities?)

---

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [September 21, 2020, 6:27pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/4 "2020-09-21T18:27:22Z")

</div>

Hi Brandon,

Yes they can. Plus, I can confirm that the filter `['shots.Shot.sg_episode.CustomEntity01.code', 'is', 'ep01']` is not a problem at all, neither is querying for `shots` directly. However, when querying for `shots.Shot.sg_status_list` or similar, it’s guaranteed that the resulting dicts won’t have that key in them.

---

<div class="post-metadata">

**Author:** ![brandon.foster](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/brandon.foster/32/91_2.png) [@brandon.foster](https://community.shotgridsoftware.com/u/brandon.foster)\
**Post date:** [September 21, 2020, 7:16pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/5 "2020-09-21T19:16:52Z")

</div>

Thanks for checking the permissions. I’ll ask the rest of the team here to see what I may be missing as part of the equation.

---

<div class="post-metadata">

**Author:** ![Ben\_xzj](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/ben_xzj/32/289_2.png) [@Ben\_xzj](https://community.shotgridsoftware.com/u/Ben_xzj)\
**Post date:** [September 22, 2020, 1:59am UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/8 "2020-09-22T01:59:15Z")

</div>

Hi @Unai,

Jumping in here to share with you what tech experts explained. Check [this post from Pat](https://community.shotgridsoftware.com/t/using-linked-fields-aka-bubbled-fields-in-api-requests/8697).

Specifically, that you can’t link through multi-entity fields to get a specific result:

> You should know, however, that you can’t use linked filter syntax in a field list if one of the links in your path is a multi-entity link. By definition, a multi-entity link you hop through would have to follow multiple paths and there’s currently no way to reflect that in a result set.
> 
> For example, in the following, it would be impossible to flow through all tasks to return multiple statuses:
> 
> `shots = sg.find('Shot', [['id', 'is', 1234]], ['tasks.Task.sg_status_list'])`

---

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [September 22, 2020, 8:55am UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/9 "2020-09-22T08:55:24Z")

</div>

Thanks guys, that makes perfect sense.

What the code I fixed yesterday suggests though, is that before 8.17, the `shots` variable in your example would be:

```python
[{'type': 'Shot', 'id': 1234, 'tasks.Task.sg_status_list': [
    {'type': 'Task', 'id': 123, 'name': 'aTask'},
    {'type': 'Task', 'id': 456, 'name': 'anotherTask'},
    ...]}]

```

While after 8.17, it’s:

```python
[{'type': 'Shot', 'id': 1234}]

```

Can we confirm this?

---

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [October 8, 2020, 10:29am UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/10 "2020-10-08T10:29:27Z")

</div>

I’ll take the silence as a yes.

---

<div class="post-metadata">

**Author:** ![brandon.foster](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/brandon.foster/32/91_2.png) [@brandon.foster](https://community.shotgridsoftware.com/u/brandon.foster)\
**Post date:** [October 8, 2020, 1:24pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/11 "2020-10-08T13:24:47Z")

</div>

Hey Unai,

Sorry for the radio silence here. We’ll check with the engineers and report back.

---

<div class="post-metadata">

**Author:** ![brandon.foster](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/brandon.foster/32/91_2.png) [@brandon.foster](https://community.shotgridsoftware.com/u/brandon.foster)\
**Post date:** [October 8, 2020, 7:13pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/13 "2020-10-08T19:13:57Z")

</div>

Hi Unai,

Just spoke with the engineers, and here’s what I learned. With the more strict enforcement of how data is accessed through bubbled fields, this is indeed a result of that. You never could request the bubbled task status through the `tasks.Task.sg_status_list` field, but it looks like we (incorrectly) were returning a Task list anyway. You can still get this result by requesting the `tasks` field if you need that list of Tasks.

I apologize if you were reliant on this shortcoming and it changed out from under you. Glad to hear you were able to make a fix, though.

---

<div class="post-metadata">

**Author:** ![Unai](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/unai/32/6119_2.png) [@Unai](https://community.shotgridsoftware.com/u/Unai)\
**Post date:** [October 14, 2020, 5:04pm UTC](https://community.shotgridsoftware.com/t/dot-notation-query-through-multi-entity-field/10132/14 "2020-10-14T17:04:59Z")

</div>

Makes complete sense Brandon. Thanks for clarifying! 😊
