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

Skiptoken cannot be generated with a DateTime value #1953

Closed
Galad opened this issue Nov 9, 2019 · 3 comments
Closed

Skiptoken cannot be generated with a DateTime value #1953

Galad opened this issue Nov 9, 2019 · 3 comments
Labels

Comments

@Galad
Copy link
Contributor

Galad commented Nov 9, 2019

Given the following entity CLR type

    public class Date
    {
        [Key]
        public DateTime DateValue { get; set; }
    }

The skiptoken value cannot be generated and throws an exception.

Assemblies affected

OData WebApi lib 7.6.1

Reproduce steps

Create an OData endpoint with the following configuration:

    public class Date
    {
        [Key]
        public DateTime DateValue { get; set; }
    }

public static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
        {
            var builder = configuration.CreateConventionModelBuilder();
            builder.EntitySet<Date>("Dates");
            IEdmModel model = builder.GetEdmModel();
            return model;
        }

    public class DatesController : TestODataController
    {
        private static readonly DateTime _baseDate = new DateTime(2019, 11, 09, 0, 0, 0, DateTimeKind.Utc);
        private readonly List<Date> _dates = Enumerable.Range(0, 5).Select(i => new Date() { DateValue = _baseDate.AddSeconds(i) }).ToList();

        [EnableQuery]
        public List<Date> Get() => _dates;
    }

Query the endpoint /Dates.

Expected result

Skiptoken is correctly generated with the value of the last record in the page.

Actual result

Exception (resulting in HTTP 500 error):

Microsoft.OData.ODataException: 'The type 'System.DateTime' is not supported when converting to a URI literal.'

Additional detail

The cause is that conversion from DateTime of DateTimeOffset in not implemented in DefaultSkipTokenHandler

@figuerres
Copy link

any word on when this pr will be part of a release?
i just started a project and ran into this bug.
i am not sure how to impliment the custom next link to work around this and would really like to see the issue fixed so that i would not need to get into the guts of how OData works.

@KanishManuja-MS
Copy link
Contributor

KanishManuja-MS commented Jan 29, 2020

@figuerres Our next priority is another WebAPI release. I believe it may take somewhere around 2-3 weeks to ship out a release. We have not settled on a date yet. Please let me know if you have a certain deadline to meet, I will let you know if that fits into our plan. We are also planning a beta version release but things are not set in stone yet.

Otherwise, I can help you with setting up the custom paging, which should not take more an hour to implement.

@figuerres
Copy link

@KanishManuja-MS sorry for the delay in the reply.
i had to just pull the current code and put in the changes made in the pr that fixes the problem.
i was able to build the dll on my local machine and use that in place of the packaged one. it works and now i can pass a date.
when the pr has been taken in and an update is published i will update to follow the released package.
by the way: seems like there are some issues with the routing, i can access my controllers as if they were just web api or as if there are OData and that is kind of confusing at first. also i am not sure but the way i currently have things setup i can not make the normal Get single record by id work.
i am working around that for now till i can figure out what the root problem is.

KanishManuja-MS pushed a commit to KanishManuja-MS/WebApi that referenced this issue Feb 25, 2020
@xuzhg xuzhg closed this as completed in 7f1c284 Mar 2, 2020
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