Skip to content

Truth value of QgsLayerTreeNode changes between QGIS3 and QGIS4 #65755

Description

@YoannQDQ

What is the bug or the crash?

In QGIS3, the truth value of a QgsLayerTreeNode (layer or group) was always True.

This allowed to write the following

layer_id = "my_id"
node = QgsProject.instance().layerTreeRoot().findLayer(layer_id)
if node:
    # Process node
    ...

In QGIS4 the truth value of a QgsLayerTreeLayer is always False, and True only for QgsLayerTreeGroup with child nodes.

Steps to reproduce the issue

QGIS4

>>> bool(QgsLayerTreeLayer(""))
False

QGIS3

>>> bool(QgsLayerTreeLayer(""))
True

Versions

QGIS 3.44.8 vs QGIS 4.0.0

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

No Duplicate of the Issue

  • I have verified that there are no existing issues raised related to my problem.

Additional context

No response

Metadata

Metadata

Assignees

Labels

BugEither a bug report, or a bug fix. Let's hope for the latter!PyQGISRelated to the PyQGIS APIRegressionSomething which used to work, but doesn't anymore

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions