airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Use sentinel to elide the dag object on reserialization

Open dstandish opened this issue 1 year ago • 13 comments
trafficstars

When we pass a task over RPC call we can't include the dag as part of the task without running into recursion trouble. So we just "elide" the dag from the task object, require that it be passed separately and then get reattatched to the task after deserialization. We introduce a sentinel so that way we can raise a helpful error if someone tries to access the dag attr after it's been elided. Additionally, the sentinel lets us short circuit some logic in the task.dag setter that is not helpful.

The motivator for this PR is avoiding conditional code like this:

    # when taking task over RPC, we need to add the dag back
    if isinstance(task, MappedOperator):
        if not task.dag:
            task.dag = dag
    elif not task._dag:
        task._dag = dag

And the idea for this approach came from a discussion with @uranusjr .

The addition of method get_relevant_upstream_map_indexes to the pydantic TI model is just a driveby addition and i can split it out if necessary.

dstandish avatar May 24 '24 21:05 dstandish

You might wanna read this section of the docs.

TL;DR: add the nodrag class name to elements that should not initiate a drag action inside a node.

bcakmakoglu avatar May 16 '24 09:05 bcakmakoglu

But that only prevents dragging the node, and you still cannot start drag selection from inside the node.

hiepnguyen3001 avatar May 17 '24 03:05 hiepnguyen3001

Well, add some css to the element user-select: text; or all and you're good.

bcakmakoglu avatar May 17 '24 05:05 bcakmakoglu

I did and it still doesn't work.

https://github.com/xyflow/xyflow/assets/139328005/c8e81e0f-6259-458f-b839-e15efb395da6

hiepnguyen3001 avatar May 17 '24 06:05 hiepnguyen3001

Mh... not quite sure what the video is supposed to tell me? What exactly are you trying to achieve with "dragging" here?

bcakmakoglu avatar May 17 '24 06:05 bcakmakoglu

In the video I start dragging outside of the box it triggers drag selection but when I do it from inside the box nothing happens.

hiepnguyen3001 avatar May 17 '24 10:05 hiepnguyen3001

Aha! Well that's quite different from the original issue I assumed you had (thought you were trying to use some input text selection or whatever inside of a node, which the above class name + css would've allowed). So the problem is using the RF built-in selection box while having the mouse on a node, is that correct?

bcakmakoglu avatar May 17 '24 10:05 bcakmakoglu

If that's the case, I don't think that works out of the box sadly - so your initial request might make sense although that's for the maintainers to decide and not me 😄

At least we were able to clarify what the exact issue here is ^^

bcakmakoglu avatar May 17 '24 10:05 bcakmakoglu

That's a good question @hiepnguyen3001. Unfortunately this is only possible with a workaround. You could listen to the selection key and set nodesDraggable={false} for example. Would that work?

moklick avatar Jun 02 '24 10:06 moklick

That's a good question @hiepnguyen3001. Unfortunately this is only possible with a workaround. You could listen to the selection key and set nodesDraggable={false} for example. Would that work?

I don't think so @moklick. Even when I set nodesDraggable={false}, it's still not possible to start a selection box from inside a node.

hiepnguyen3001 avatar Jun 03 '24 06:06 hiepnguyen3001

Damn.. The only way I see then is to add a class or set a style directly that prevents all pointer events.

moklick avatar Jun 03 '24 09:06 moklick

pointer-events: none; on the node that you want to start the drag selection in worked for me.

MatheusRoichman avatar Sep 24 '24 02:09 MatheusRoichman

We needed this as well and found the same workaround with pointer-events: none; You can still have other elements inside your Group node that do have pointer events.

Basically we wanted the inner part of a Group node to act more like the Pane. Additionaly, we wanted the Group node itself to be not selectable by default when using the selection rectangle. Our hacky solution for that was;

  useEffect(() => {
    // Selectable group nodes only when spacekey is pressed
     if (spaceKeyPressed) {
      updateNode(props.id, { selectable: true });
    } else {
      updateNode(props.id, { selectable: false });
    }
  }, [updateNode, props.id, spaceKeyPressed]);

// note: we use a custom store for the nodes, so the reactflow way looks a bit different

There are more things that could still be improved with Group nodes, but the recent update was already nice to see.

heavy-d avatar Oct 13 '24 22:10 heavy-d

If you need this feature, the workaround is to set pointer-events: none.

moklick avatar May 12 '25 13:05 moklick