Skip to content

Issue using a dataset router with mutliple datasets #310

@Jakidxav

Description

@Jakidxav

I am relatively new to Xpublish and am trying to follow the Serving multiple datasets tutorial. The docs say that using custom routes for multiple datasets should work just like they do for single datasets. However, I can't seem to get the example to work.

Possibly related:

Here is the code that I adapted from the Xpublish tutorial.

import xarray as xr
import xpublish
from xpublish.dependencies import get_dataset
from fastapi import APIRouter, Depends, HTTPException

ds = xr.tutorial.open_dataset('air_temperature', chunks=dict(lat=5, lon=5),)
ds2 = xr.tutorial.open_dataset('rasm')

ds_collection = {
    'air_temperature': ds,
    'rasm': ds2,
}

router = APIRouter()

@router.get('/{var_name}/mean')
def get_mean(var_name: str, dataset: xr.Dataset = Depends(get_dataset)):
    if var_name not in dataset.variables:
        raise HTTPException(
            status_code=404, detail=f"Variable '{var_name}' not found in dataset"
        )

    return float(dataset[var_name].mean())

rest_collection = xpublish.Rest(ds_collection, routers=[router])
rest_collection.serve()

When I try and run this example, however, I get the following error:

ValueError: Duplicated param name dataset_id at path /datasets/{dataset_id}/datasets/{dataset_id}/{var_name}

Am I doing something wrong here? I seem to be triggering the error raised in the xpublish.utils.api.check_route_conflicts() method because the /datasets/{datasets_id}/ path is repeated. If I am understanding other Github issues and discussions, it seems like I may need to serve up separate datasets on individual ports within the same app, is that right?

Any help or advice would be much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions