Fix #119030: Only access Location node input when available #119354

Merged
Jesse Yurkovich merged 4 commits from deadpin/blender:fix119030-nodelookup into blender-v4.1-release 2024-03-13 05:22:53 +01:00

Our node_shader_utils.py module needs to be updated to account for API
changes made during the 4.0 release cycle [1].

Here we need to guard against accessing the "Location" node input if not
dealing with the appropriate type of Mapping node.

[1] e4ad58114b

Our `node_shader_utils.py` module needs to be updated to account for API changes made during the 4.0 release cycle [1]. Here we need to guard against accessing the "Location" node input if not dealing with the appropriate type of Mapping node. [1] e4ad58114b9d56fe838396a97fe09aff32c79c6a
Jesse Yurkovich added 1 commit 2024-03-12 00:52:11 +01:00
Thomas Barlow reviewed 2024-03-12 02:15:26 +01:00
@ -799,3 +799,3 @@
def translation_get(self):
if self.node_mapping is None:
if self.node_mapping is None or self.node_mapping.vector_type not in ('POINT', 'TEXTURE'):
Member

.__contains__ also respects input/output availability, so I think it would be more robust to use

if self.node_mapping is None or "Location" not in self.node_mapping.inputs:

than checking for specific vector_type values.

`.__contains__` also respects input/output availability, so I think it would be more robust to use ```py if self.node_mapping is None or "Location" not in self.node_mapping.inputs: ``` than checking for specific `vector_type` values.
deadpin marked this conversation as resolved
Jesse Yurkovich added 1 commit 2024-03-12 02:47:35 +01:00
Iliya Katushenock added this to the Nodes & Physics project 2024-03-12 06:16:24 +01:00
Iliya Katushenock added the
Module
Python API
label 2024-03-12 06:16:28 +01:00
Author
Member

@JacquesLucke How do you feel about the fix here? It handles the problem at the common api location, to mimic the prior behavior, rather than the downstream call site.

@JacquesLucke How do you feel about the fix here? It handles the problem at the common api location, to mimic the prior behavior, rather than the downstream call site.
Jacques Lucke approved these changes 2024-03-12 10:03:08 +01:00
Jacques Lucke left a comment
Member

LGTM.

LGTM.

This patch will fix the reported issue, but I think it should get more generic, since there potentially are (or will be) other sockets hidden that way? Feels like all accesses to a node's sockets should be protected now?

This patch will fix the reported issue, but I think it should get more generic, since there potentially are (or will be) other sockets hidden that way? Feels like all accesses to a node's sockets should be protected now?
Jesse Yurkovich added 1 commit 2024-03-12 19:58:55 +01:00
Author
Member

@mont29 I added a set of helper methods that can make future changes easier but I'm not sure about protecting all such accesses at the moment. There's close to 50 other accesses in this file alone that would have to be inspected.

@mont29 I added a set of helper methods that can make future changes easier but I'm not sure about protecting all such accesses at the moment. There's close to 50 other accesses in this file alone that would have to be inspected.
Bastien Montagne approved these changes 2024-03-13 02:59:31 +01:00
Bastien Montagne left a comment
Owner

LGTM, especially for 4.1.

@JacquesLucke the change in e4ad58114b is very... questionable to me. Having keys listed in keys() but returning KeyError with item subscription is very disturbing from a Python PoV. At the very (very) least, I would have expected a complete detailed explanation of that new behavior in the API docs of Node.inputs and Node.outputs.

@deadpin Indeed checking all cases that can potentially need these protected accessors (or deciding to always use them) can be done later. IMHO it should also cover outputs.

Also not for this PR, but for a later improvement (could be good to add a comment about it now though): I would move this check into its own utils, and make it a bit more 'safe' by checking that the key is actually defined in the inputs (or outputs), with something like that:

def node_socket_key_validate(node, sockets, socket_key):
    if node is None:
        return false
    # Since Blender 4.0 (e4ad58114b), if a socket is not 'valid' given current node's settings,
    # it is 'hidden' from regular name-based subscription. However the key is still expected to
    # be present in `sockets.keys()`.
    if socket_key not in sockets.keys();
        raise KeyError(f"{socket_key} is not a valid socket identifier for node {node.name}").
    if socket_key not in sockets:
        return false
    return true
LGTM, especially for 4.1. @JacquesLucke the change in e4ad58114b is very... questionable to me. Having keys listed in `keys()` but returning KeyError with item subscription is very disturbing from a Python PoV. At the very (very) least, I would have expected a complete detailed explanation of that new behavior in the API docs of `Node.inputs` and `Node.outputs`. @deadpin Indeed checking all cases that can potentially need these protected accessors (or deciding to always use them) can be done later. IMHO it should also cover outputs. Also not for this PR, but for a later improvement (could be good to add a comment about it now though): I would move this check into its own utils, and make it a bit more 'safe' by checking that the key is actually defined in the inputs (or outputs), with something like that: ``` def node_socket_key_validate(node, sockets, socket_key): if node is None: return false # Since Blender 4.0 (e4ad58114b), if a socket is not 'valid' given current node's settings, # it is 'hidden' from regular name-based subscription. However the key is still expected to # be present in `sockets.keys()`. if socket_key not in sockets.keys(); raise KeyError(f"{socket_key} is not a valid socket identifier for node {node.name}"). if socket_key not in sockets: return false return true ```
Jesse Yurkovich added 1 commit 2024-03-13 05:22:18 +01:00
Jesse Yurkovich merged commit 0b19f1f4a0 into blender-v4.1-release 2024-03-13 05:22:53 +01:00
Jesse Yurkovich deleted branch fix119030-nodelookup 2024-03-13 05:22:59 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119354
No description provided.