# Problem using CustomNonProjectEntity in schema

**URL:** <https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828>\
**Category:** Pipeline Integrations\
**Created:** [February 25, 2022, 2:52pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828 "2022-02-25T14:52:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [February 25, 2022, 2:52pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/1 "2022-02-25T14:52:10Z")

</div>

Hi there,  
I’m experimenting with the potential of using a customNonProjectEntity in our schema.  
I’ve added a “task\_group” entity field field to my Task entity which links to my customNonProjectEntity.  
In the schema I’ve defined the folder for this “task\_group” to be a “Task” entity type folder, with the following yml definition

```auto
type: "shotgun_entity"
name: "code"
entity_type: "Task"
filters: [{ "path": "sg_task_group.CustomNonProjectEntity03.code", "relation": "is", "values": [ "$task"] } ]

```

When I try to create folders on a task, I get an error suggesting tk requires the entity to be associated with a project, eg not a CustomNonProjectEntity, but a CustomEntity instead.

Is this a hard limitation I won’t be able to overcome here?

Thanks in advance for your assistance.  
p.

---

<div class="post-metadata">

**Author:** ![mmoshev](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/mmoshev/32/476_2.png) [@mmoshev](https://community.shotgridsoftware.com/u/mmoshev)\
**Post date:** [February 28, 2022, 8:15am UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/2 "2022-02-28T08:15:00Z")

</div>

I don’t know, but strongly suspect it _is_ a hard limitation.

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [February 28, 2022, 3:05pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/3 "2022-02-28T15:05:20Z")

</div>

Thanks Mois!  
This documentation suggests this might be possible via a custom pipeline step entity :  
[Filesystem Configuration Reference - SG Developer (shotgridsoftware.com)](https://developer.shotgridsoftware.com/82ff76f7/?title=Filesystem+Configuration+Reference#how-can-i-create-a-custom-pipeline-step-using-a-custom-entity)

I can’t figure out how to implement it though… initial attempts were unsuccessful.  
I’ve raised a specific ticket for this here : [Request for example code using “sg\_task\_type” for “custom Pipeline Step using a custom entity” - Community @ ShotGrid (shotgridsoftware.com)](https://community.shotgridsoftware.com/t/request-for-example-code-using-sg-task-type-for-custom-pipeline-step-using-a-custom-entity/14839)

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [February 28, 2022, 9:55pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/4 "2022-02-28T21:55:38Z")

</div>

I managed to get this working actually… using the trick of making the customNonProjectEntity a custom pipeline step, as per the ticket I posted above.

The only problem is that it looks like we need to fork tk-core so we can override the hard-coded logic that would cause tk.context\_from\_path to return only the parent folders entity as the entity of a context; for this use case, we don’t want that, we still want context\_from\_path to return the Shot context, (in the same way as with the custom “step” folder, we explicitly set the line `associated_entity_type: Shot`  
see [Filesystem Configuration Reference - SG Developer (shotgridsoftware.com)](https://developer.shotgridsoftware.com/82ff76f7/?title=Filesystem+Configuration+Reference#advanced---specify-a-parent))

Otherwise, although the schema and templates are setup correctly to use the // path form, when it comes to apps that use `context_from_path`, you get problems with the context entity being the entity, NOT the Shot entity, which is what we would typically want.

I think I’ll wrap that up in a new core hook.

@sg-devs @sg-support, in tank.context can you see any reason why we can’t abstract the final context object via a hook to allow user customisation of context handling without forking core?  
eg this section of the method :

```auto
for curr_entity in entities[::-1]:
        # handle the special context fields first
        if curr_entity["type"] == "Project":
            context["project"] = curr_entity
        elif curr_entity["type"] == "Step":
            context["step"] = curr_entity
        elif curr_entity["type"] == "Task":
            context["task"] = curr_entity
        elif curr_entity["type"] == "HumanUser":
            context["user"] = curr_entity

        # THIS BIT IS WHAT WE NEED TO ADD TO GET THIS ALL TO WORK
        elif curr_entity["type"] == "CustomNonProjectEntity03":
            context["my_custom_entity"] = curr_entity
        ###################################################

        elif curr_entity["type"] in additional_types:
            context["additional_entities"].append(curr_entity)
        else:
            context["entity"] = curr_entity

```

I’d propose a hook called something like “context\_create\_dict” with the above code.

---

<div class="post-metadata">

**Author:** ![Halil](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/halil/32/4697_2.png) [@Halil](https://community.shotgridsoftware.com/u/Halil)\
**Post date:** [March 1, 2022, 2:38am UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/6 "2022-03-01T02:38:01Z")

</div>

I initially deleted my post after reading you actually got this working but it wasn’t doing exactly what you wanted but for reference on the topic in general for anyone else:

We are doing the exact same thing and grouping Tasks by a StepGroup/Department entity.

```auto
In the folder configuration, add two special options to tell it to use your custom step setup rather than ShotGrid’s built-in Pipeline Step:

entity_type: "CustomNonProjectEntity05"
task_link_field: "sg_task_type"

```

Where `task_link_field` value is a custom `entity` data type field on a Task entity that links to your new CustomNonProjectEntity.

> **[ShotGrid Developer](https://developer.shotgridsoftware.com/82ff76f7/#how-can-i-create-a-custom-pipeline-step-using-a-custom-entity)**
>
> This site contains detailed technical reference for all of the ways you can interact with ShotGrid programmatically, as well as tutorials, guides, and other educational resources for learning how to make the best use of all of ShotGrid's integration...

The following hook then assists in querying this entity when generating a context:

> <https://github.com/shotgunsoftware/tk-core/blob/master/python/tank/context.py#L1562-L1565>

> <https://github.com/shotgunsoftware/tk-core/blob/2fc8287a19f8f002e23101836bafba0ec0de9dc9/hooks/context_additional_entities.py#L24-L28>

You can then see how this is then used when interacting with the schema:

> <https://github.com/shotgunsoftware/tk-core/blob/2fc8287a19f8f002e23101836bafba0ec0de9dc9/python/tank/folder/operations.py#L176-L186>

---

<div class="post-metadata">

**Author:** ![mmoshev](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/mmoshev/32/476_2.png) [@mmoshev](https://community.shotgridsoftware.com/u/mmoshev)\
**Post date:** [March 1, 2022, 8:01am UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/7 "2022-03-01T08:01:22Z")

</div>

Nice job for getting it working. But I mean, if you would have to hack core, then you could have any entity at all in the context. Does it still need to be related to the task? Why not to other entities?

Instead of a hook, I would like a solution that reads the custom entity types _from the schema_ which is already a logical place for this information.

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [March 1, 2022, 12:07pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/8 "2022-03-01T12:07:49Z")

</div>

The entity I’m grouping by is a CustomNonProjectEntity so I don’t want publishes or versions linked to it specifically. I want them to be linked to the Shot as usual.

I think the specific case I have here is I want my custom Step entity AND the normal Step entities; so the problem in context.py is that it’s hard coded that the context Entity object is simply the last one contained in the path\_cache, even if it’s a “Step” or “CustomNonProjectentity”.

eg `<shot>/<my_custom_entity>/<step>/<etc>`

I like the idea of fixing this via the schema, but I think that’s outside the realm of work I want to tackle to fix this. Abstracting this snippet of code to a hook is simple, and allows for easy customisation.

My example above adds my customNonProjectentity to a custom context attribute, but that’s only a means to an end of ensuring that the “Shot” is the actual context[‘entity’] value here. I could just as easily set it to :

```auto
        # THIS BIT IS WHAT WE NEED TO ADD TO GET THIS ALL TO WORK
        elif curr_entity["type"] == "CustomNonProjectEntity03":
            continue

```

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [March 1, 2022, 12:10pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/9 "2022-03-01T12:10:57Z")

</div>

Thanks Halil!  
Yes that is the solution I found too.  
One thing I wanted to avoid was relying on the depreciated Context\_additional\_entities hook.

It does seem useful though, I wonder why it was depricated? @sg-support ?

---

<div class="post-metadata">

**Author:** ![eric.cabot](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eric.cabot](https://community.shotgridsoftware.com/u/eric.cabot)\
**Post date:** [March 1, 2022, 3:34pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/10 "2022-03-01T15:34:07Z")

</div>

hello why do you say it was deprecated? what was deprecated exactly?

---

<div class="post-metadata">

**Author:** ![Halil](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/halil/32/4697_2.png) [@Halil](https://community.shotgridsoftware.com/u/Halil)\
**Post date:** [March 1, 2022, 10:31pm UTC](https://community.shotgridsoftware.com/t/problem-using-customnonprojectentity-in-schema/14828/11 "2022-03-01T22:31:35Z")

</div>

> <https://github.com/shotgunsoftware/tk-core/blob/2fc8287a19f8f002e23101836bafba0ec0de9dc9/hooks/context_additional_entities.py#L14-L19>
