Azure / Azure/AzureGraph

`call_graph_url()` serializes POSIXct body fields as ambiguous, offset-less datetime strings

Ouverte
#40 3 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
R
Étoiles
38
Forks
22
Merge moyen
2 j 8 h
PR mergées (30 j)
1

Description

`call_graph_url()` serializes JSON request bodies with:

```
# R/call_graph.R, call_graph_url()
body <- jsonlite::toJSON(body[!null], auto_unbox = TRUE, digits = 22, null = "null")
```

This uses jsonlite's default POSIXt = "string" handling, which calls format()/as.character() on POSIXct values. That respects the object's tzone attribute but appends no UTC offset or "Z" suffix, so the resulting string is ambiguous about what instant it represents.

Microsoft Graph's OData Edm.DateTimeOffset fields expect an explicit ISO 8601 string with a Z or numeric offset (e.g. "2022-07-31T14:05:19Z"); sending a bare "2022-07-31 14:05:19" leaves Graph to guess the offset, which I think resolves against the site/tenant's regional timezone, silently shifting the stored instant away from the value the caller intended.

``` r
library(jsonlite)

x <- as.POSIXct(1659276319, origin = "1970-01-01", tz = "UTC")

# This mirrors call_graph_url()'s exact serialization call:
jsonlite::toJSON(
list(dateTimeField = x),
auto_unbox = TRUE,
digits = 22,
null = "null"
)
#> {"dateTimeField":"2022-07-31 14:05:19"}

# Confirming it's not just a formatting-style choice: jsonlite's "ISO8601"
# option has the same ambiguity, just with a "T" separator instead of a space
jsonlite::toJSON(list(dateTimeField = x), POSIXt = "ISO8601", auto_unbox = TRUE)
#> {"dateTimeField":"2022-07-31T14:05:19"}
# still no "Z"/offset

# The only unambiguous encoding requires explicit UTC formatting:
strftime(x, "%Y-%m-%dT%H:%M:%SZ", tz = "UTC")
#> [1] "2022-07-31T14:05:19Z"
```

Created on 2026-09-09 with [reprex v2.1.1](https://reprex.tidyverse.org)

**Expected:** A POSIXct value passed in a request body to call_graph_url() should serialize to an unambiguous ISO 8601 UTC string (...Z) matching what Graph's OData Edm.DateTimeOffset fields expect, regardless of the POSIXct object's tzone attribute or the caller's Sys.timezone().

**Actual:** The serialized string carries no UTC marker at all, so any Graph endpoint accepting a dateTime/DateTimeOffset field is handed an ambiguous value whenever a caller passes a native POSIXct.

**Suggested fix:** In call_graph_url(), before calling jsonlite::toJSON(), recursively convert any POSIXct (and Date) elements of body to explicit UTC ISO 8601 strings, e.g. `strftime(x, "%Y-%m-%dT%H:%M:%SZ", tz = "UTC")` for POSIXct and `strftime(x, "%Y-%m-%d", tz = "UTC")` for Date. Neither of jsonlite's built-in POSIXt options ("string", "ISO8601") is sufficient on their own, since neither appends a UTC offset.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez dans R/call_graph.R, au niveau de call_graph_url(), et reproduisez la sortie JSON présentée dans l’issue avec une valeur POSIXct. Suivez la manière dont les valeurs du corps de la requête sont sérialisées, puis vérifiez que les valeurs POSIXct deviennent des chaînes UTC ISO 8601 se terminant par Z et que les valeurs Date utilisent le format de date attendu, y compris lorsqu’elles sont imbriquées dans le corps.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
r
Domaine
api
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
75/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.