Skip to content

Dataset modification in Reader.__attrs_post_init__ is overwritten by base class initialization #111

@alexandre-borowczyk

Description

@alexandre-borowczyk

titiler-multidim version: v0.7.1

Description:
I'm working with a ZARR 4D dataset (T, Z, Y, X) where the time dimension T always has length 1 and needs to be squeezed for proper processing. I attempted to modify the dataset after the self.opener call in Reader.__attrs_post_init__, but discovered that modifications are overwritten during initialization.

Note: This makes caching logic also ineffective

Root Cause:
The dataset is subsequently set in the base class titiler.xarray.io.Reader.__attrs_post_init__, which overwrites any modifications made in the multidim-specific Reader subclass before the super().__attrs_post_init__()call.
Proposed Solution:
I've resolved this by modifying titiler.multidim.reader.Reader.__attrs_post_init__:

# Add this block to set self.input before base class initialization
self.input = get_variable(
    self.ds,
    self.variable,
    sel=self.sel,
    method=self.method,
)

# Change from super().__attrs_post_init__() to:
super(Reader, self).__attrs_post_init__()

This ensures dataset modifications persist by setting self.input before the base class processes it, and the explicit super(Reader, self).__attrs_post_init__() call skips the immediate parent's reinitialization.

Question:
I'm happy to submit a pull request with this fix, but as I'm new to titiler, I want to ensure this aligns with the intended initialization workflow. Is this the correct approach for applying dataset transformations in subclasses, or would you prefer a different pattern?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions