OData / OData/AspNetCoreOData

POST Action with DateTime in Model causes an not handlable exception which is never passed to client

Open
#955 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
ASP.NET Core OData 8.x

Describe the bug
When I create a Post Action in an OdataController, the conversion of DateTime in it produces an internal OdataException, which cannot be catched.

Reproduce steps

  1. Create a OdataController with a POST Action
  2. Create a Model with a DateTime Field in it.
  3. Call the endpoint with the DateTime Field passed as a string in format YYYY-MM-ddThh:mm:ss.
  4. An exception is found when putting a debug in the action (in Rider it is stored in a $exception)

Data Model

public class WeatherForecast
{

    public int Id {get; set;}

    public DateTime? Date { get; set; }

    public int TemperatureC { get; set; }

    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

    public string? Summary { get; set; }
}

Expected behavior
The error is passed to the client automatic or can be catched with UseExceptionHandler().

Screenshots
If applicable, add screenshots to help explain your problem.
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the POST action in an ASP.NET Core OData 8.x OdataController with the WeatherForecast model and its nullable DateTime field, using the YYYY-MM-ddThh:mm:ss payload described. Trace where the internal ODataException occurs before the action and how UseExceptionHandler receives it. Done means the error is automatically returned to the client or can be caught by UseExceptionHandler.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.