Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If you specify template_from when creating child node (a Component), it will be created as a root project #10654

Open
hidefumi-moritani opened this issue Jun 27, 2024 · 0 comments

Comments

@hidefumi-moritani
Copy link

We have detected an issue that appears to be a bug, and would like to report it below.

Steps

  1. Create a child node (component) by calling the API with the attribute template_from.

Expected

Expect child node (a Component) to be created successfully.

Actual

Create as a root node (project) instead of a child node(a Component).

Note:

When a template_from is specified in the API, in the NodeSerializer class, the Node is always created as the root Project.

https://github.com/CenterForOpenScience/osf.io/blob/develop/api/nodes/serializers.py#L794-L805

        if 'template_from' in validated_data:
            template_from = validated_data.pop('template_from')
            template_node = Node.load(template_from)
            if template_node is None:
                raise exceptions.NotFound
            if not template_node.has_permission(user, osf_permissions.READ, check_parent=False):
                raise exceptions.PermissionDenied
            validated_data.pop('creator')
            changed_data = {template_from: validated_data}
            node = template_node.use_as_template(auth=get_user_auth(request), changes=changed_data)
        else:
            node = Node(**validated_data)

If it is other than template_from, specify parent in Node init.

https://github.com/CenterForOpenScience/osf.io/blob/develop/osf/models/node.py#L474-L477

    def __init__(self, *args, **kwargs):
        self._parent = kwargs.pop('parent', None)
        self._is_templated_clone = False
        super(AbstractNode, self).__init__(*args, **kwargs)

If template_from and parent Node are specified in the API, one idea is to specify them in node._parent.

RCOSDP@272446a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant