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

Timeseries POST gives Null Pointer for null Values #876

Open
krowvin opened this issue Sep 17, 2024 · 2 comments
Open

Timeseries POST gives Null Pointer for null Values #876

krowvin opened this issue Sep 17, 2024 · 2 comments
Labels
bug Something isn't working timeseries

Comments

@krowvin
Copy link
Collaborator

krowvin commented Sep 17, 2024

Using POST for Timeseries to set NULL values

Background

Working with @inguyen314 we were discussing the finer points of how to replace-all values in a timeseries with null values.

The idea being you want to write some data from a future forecast, but other data you'd want to make sure was null. Or perhaps the forecast changes and those values are now null for those dates.

Agreement

We both agreed that one should be able to interlace null values in a valid POST request where you may also want to write valid values.

Workaround

One could of course call the DELETE method and specify the date range.

Reasons not to?

But in our humble opinion Why not both?

Example

Doing the following results in a NULL POINTER exception in the logs:

  const payloadDeleteGraysPt = {
                    "name": "Grays Pt-Mississippi.Stage.Inst.~1Day.0.netmiss-fcst",
                    "office-id": "MVS",
                    "units": "ft",
                    "values": [
                        [
                            getDateWithTimeSet(0, 6, 0),
                            null,
                            0
                        ],
                        [
                            getDateWithTimeSet(1, 6, 0),
                            8675309,
                            0
                        ],
                        [
                            getDateWithTimeSet(2, 6, 0),
                            8675309,
                            0
                        ],
                        [
                            getDateWithTimeSet(3, 6, 0),
                            null,
                            0
                        ],
                        [
                            getDateWithTimeSet(4, 6, 0),
                            null,
                            0
                        ],
                        [
                            getDateWithTimeSet(5, 6, 0),
                            null,
                            0
                        ],
                        [
                            getDateWithTimeSet(6, 6, 0),
                            null,
                            0
                        ],
                    ]

This was done in javascript. I do not have a CURL command readily available but here is the Vanilla JS done to test this:

async function deleteTS() {
    // Create an array of promises to handle multiple payloads
    let promises = payloadDelete.map(ts_payload => {
        return fetch("[https://wm.mvs.ds.usace.army.mil/mvs-data/timeseries?store-rule=REPLACE%20ALL"](https://wm.mvs.ds.usace.army.mil/mvs-data/timeseries?store-rule=REPLACE%20ALL%22), {
            method: "POST",
            headers: {
                "accept": "*/*",
                "Content-Type": "application/json;version=2",
            },
            body: JSON.stringify(ts_payload)
        }).then(async r => {
            // Get the response message and status
            const message = await r.text();
            const status = r.status;
            return { 'message': message, 'status': status };
        }).catch(error => {
            // Handle fetch errors
            return { 'message': error.message, 'status': 'fetch_error' };
        });
    });
 
    // Wait for all promises to resolve
    const return_values = await Promise.all(promises);
    console.log("Return values from deleteTS:", return_values);
 
    // Check for errors based on status and message content
    const has_errors = return_values.some(v => v.status !== 200 || v.message.includes("error") || v.message.includes("fail"));
    return has_errors;
}
@krowvin krowvin added bug Something isn't working timeseries labels Sep 17, 2024
@rma-rripken
Copy link
Collaborator

@krowvin
Copy link
Collaborator Author

krowvin commented Oct 11, 2024

@rma-rripken I was talking to Daniel about this

Does it make sense for POST to ONLY be able to create NEW timeseries values and not ALSO update existing with a null?

Because it WILL write over existing values (POST will) if there is a value given.

But I think we've established this is OK because you can update other values with values. It's just the null that doesn't work.

So then i'm not sure what the purpose of PATCH is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working timeseries
Projects
None yet
Development

No branches or pull requests

2 participants