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

Using startswith filter on CalendarView query throws 500 error if any events have no subject #2559

Closed
tsulli opened this issue Jun 24, 2024 · 5 comments
Labels

Comments

@tsulli
Copy link

tsulli commented Jun 24, 2024

Describe the bug

When querying CalendarView for user calendar events with a subject filter, Graph returns an internal server error 500 if the user has any events within the specified time frame that have no subject. This error occurs both in the SDK and in Graph Explorer.

If the Graph query filter is removed and the events are filtered with LINQ on the client site, no error is thrown.

image

image

Expected behavior

A CalendarView query with a startswith filter on the subject should return a 200 response with only events that have a subject that starts with the specified string. Events with no subject should be omitted.

How to reproduce

  1. Create and save an event on your user calendar in your tenant with no subject. It does not matter what time the event is, or if it's private.
  2. Run the following query in Graph Explorer, where the UTC start and end date include the time your subject-less event occurs and receive a 500 error response.
    For example, if your subject-less event is on June 24 at 10am EDT:
https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-06-24T14:00:00Z&endDateTime=2024-06-24T15:00:00Z&$top=10&$select=id,changeKey,isAllDay,subject,bodyPreview,start,end&$filter=startswith(subject, '[Bug]')

Repsonse:

 "error": {
        "code": "ErrorInternalServerError",
        "message": "An internal server error occurred. The operation failed."
    }

The equivalent SDK code:

string[] propertyFilter = ["id", "changeKey", "isAllDay", "subject", "bodyPreview", "start", "end"];
List<Event> onlineUserEvents = [];
EventCollectionResponse userCalendarViewCollectionPage = new();
try
{
    userCalendarViewCollectionPage = await userCalendar.CalendarView.GetAsync(reqConfig =>
    {
        reqConfig.QueryParameters.StartDateTime = $"{startDate:s}";
        reqConfig.QueryParameters.EndDateTime = $"{endDateTime:s}";
        reqConfig.QueryParameters.Top = eventsPerPage;
        reqConfig.QueryParameters.Select = propertyFilter;
        // we would like to use this filter, but as of June 2024 this breaks the query if the user has an events on their calendar
        // without a subject. This is a known issue with the Graph API.
        reqConfig.QueryParameters.Filter = $"startswith(subject, '[Bug]')";
    });

    onlineUserEvents.AddRange(userCalendarViewCollectionPage.Value
        // work around for MS Graph filtering bug
        //.Where(e => !String.IsNullOrEmpty(e.Subject) && e.Subject.StartsWith(userCalendarPrefix))
        .ToList());
}
catch (Exception e)
{
    Log.Error(e, $"Failed to read calendar for {user.Email}");
    continue;
}
  1. Change the Graph query to a time range that does NOT include your subject-less event (or remove the reqConfig.QueryParameters.Filter = $"startswith(subject, '[Bug]')"; line from the SDK query) and receive a 200 response:
https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-06-24T13:00:00Z&endDateTime=2024-06-24T14:00:00Z&$top=10&$select=id,changeKey,isAllDay,subject,bodyPreview,start,end&$filter=startswith(subject, '[Bug]')

SDK Version

5.56.0

Latest version known to work for scenario above?

No response

Known Workarounds

Removing the startswith filter from the query to return all events from Graph, then filter on the client side. For example with LINQ:

userCalendarViewCollectionPage.Value
 // Filter for startsWith and omit null subjects
.Where(e => !String.IsNullOrEmpty(e.Subject) && e.Subject.StartsWith(userCalendarPrefix))
.ToList()

Debug output

Click to expand log ```
</details>


### Configuration

- OS: Windows 11
- Architecture: Any CPU

### Other information

_No response_
@tsulli tsulli added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jun 24, 2024
@MartinM85
Copy link
Contributor

MartinM85 commented Jun 25, 2024

If the subject is not specified when an event is created, the value is null. In that case, you can modify the $filter clause and ignore events without the subject.

https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2024-06-24T14:00:00Z&endDateTime=2024-06-24T15:00:00Z&$top=10&$select=id,changeKey,isAllDay,subject,bodyPreview,start,end&$filter=subject ne null AND startswith(subject, '[Bug]')

As you mentioned that it's a known issue. Have you already reported it?

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jun 25, 2024
@tsulli
Copy link
Author

tsulli commented Jun 25, 2024

@MartinM85 The known issue comment was intended for our internal developers, not meant to imply it's an official known issue within Microsoft. We did have a Microsoft support ticket open for 2+ months related to this issue though. Thanks for pointing out that the null filter works as a work around too. I still don't believe reporting a 500 error is the intended result when using the startsWith filter without an additional null filter?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jun 25, 2024
@andrueastman
Copy link
Member

@tsulli Thanks for raising this.

As this issue is regards the behavior of the API, and this repo is mainly intended for SDK related issues, you can possibly re-open the support ticket for this to be followed up by the API team or provide feedback at https://aka.ms/graphFeedback.

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jun 26, 2024
@tsulli
Copy link
Author

tsulli commented Jun 30, 2024

@andrueastman I let all of the support folks on the ticket know about this Github issue. I've been assured it's been seen and passed on to the product team, and they will continue working on it. I've closed out the ticket since we have a work around for now.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close Status: No recent activity labels Jun 30, 2024
@andrueastman
Copy link
Member

Thanks for confirming. We'll also close this issue for now as there is no action to be done on the SDK side.
As the product team is aware, this will be followed up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants