Skip to content

DateTime issues in Update function #49

@alf

Description

@alf

This issue relates to rethinkdb/rethinkdb#5755, but I'm filing it here as well since I believe my use case would work if the driver serialized the DateTime the same way in both the insert and the update.

I'd prefer both the insert and the update to fail (by using ISO8601 serialization both places) or that both work (by using epochTime serialization both places).

Here's a simple test that illustrates my problem:

using System;
using Newtonsoft.Json;
using NUnit.Framework;
using RethinkDb.Driver;
using Should;

namespace DRIV.Common.Data.Helpers
{
    public class Test
    {
        [JsonProperty("id")]
        public int Id = 1;
        public DateTime DateTime { get; set; }

        private static RethinkDB R = RethinkDB.R;

        [SetUp]
        public void SetUp()
        {
            using (var connection = R.Connection().Connect())
            {
                R.Db("test").TableCreate("test").Run(connection);
            }
        }

        [TearDown]
        public void TearDown()
        {
            using (var connection = R.Connection().Connect())
            {
                R.Db("test").TableDrop("test").Run(connection);
            }
        }

        [Test]
        public void TestUpdateWithMinValue()
        {
            using (var connection = R.Connection().Connect())
            {
                var insertResult = R
                    .Db("test")
                    .Table("test")
                    .Insert(new Test { DateTime = DateTime.MinValue.ToUniversalTime() })
                    .RunResult(connection);
                insertResult.Errors.ShouldEqual<ulong>(0);

                var updateResult = R
                    .Db("test")
                    .Table("test")
                    .Get(Id)
                    .Update(orig =>
                    {
                        var unchanged = orig["DateTime"].Eq(DateTime.MinValue.ToUniversalTime());
                        return R.Error(unchanged.CoerceTo("string"));
                    })
                    .OptArg("return_changes", true)
                    .RunResult(connection);
                updateResult.Errors.ShouldEqual<ulong>(1);
                updateResult.FirstError.ShouldEqual("true");
            }
        }
    }
}

And here's the TRACE log from running thetest:

Should.Core.Exceptions.EqualException : Assert.Equal() Failure
Position: First difference is at position 0
Expected: true
Actual:   Error in time logic: Year is out of valid range: 1400..10000.
   at DRIV.Common.Data.Helpers.Test.TestUpdateWithMinValue() in C:\Users\alfler\Projects\driv-data\03Common\DRIV.Common.Data\Helpers\Test.cs:line 59

[TRACE] JSON Send: Token: 1, JSON: [1,[60,[[14,["test"]],"test"]],{}]
[TRACE] JSON Recv: Token: 1, JSON: {"t":1,"r":[{"config_changes":[{"new_val":{"db":"test","durability":"hard","id":"c58274be-c560-4127-8f3e-13e32a598476","indexes":[],"name":"test","primary_key":"id","shards":[{"nonvoting_replicas":[],"primary_replica":"W7L_R90H7009_6gj","replicas":["W7L_R90H7009_6gj"]}],"write_acks":"majority"},"old_val":null}],"tables_created":1}]}
[TRACE] Response Pump: EndOfStreamException - Unable to read beyond the end of the stream. The connection can no longer be used. ResponsePump is preparing to shutdown.
[TRACE] Cleaning up Response Pump awaiters for localhost:28015
[TRACE] JSON Send: Token: 1, JSON: [1,[56,[[15,[[14,["test"]],"test"]],{"id":1,"DateTime":{"$reql_type$":"TIME","epoch_time":-62135596800.0,"timezone":"+00:00"}}]],{}]
[TRACE] JSON Recv: Token: 1, JSON: {"t":1,"r":[{"deleted":0,"errors":0,"inserted":1,"replaced":0,"skipped":0,"unchanged":0}]}
[TRACE] JSON Send: Token: 2, JSON: [1,[53,[[16,[[15,[[14,["test"]],"test"]],1]],[69,[[2,[1]],[12,[[51,[[17,[[170,[[10,[1]],"DateTime"]],[99,["0001-01-01T00:00:00.0000000Z"]]]],"string"]]]]]]],{"return_changes":true}],{}]
[TRACE] JSON Recv: Token: 2, JSON: {"t":1,"r":[{"changes":[],"deleted":0,"errors":1,"first_error":"Error in time logic: Year is out of valid range: 1400..10000.","inserted":0,"replaced":0,"skipped":0,"unchanged":0}]}
[TRACE] Response Pump: EndOfStreamException - Unable to read beyond the end of the stream. The connection can no longer be used. ResponsePump is preparing to shutdown.
[TRACE] Cleaning up Response Pump awaiters for localhost:28015
[TRACE] JSON Send: Token: 1, JSON: [1,[61,[[14,["test"]],"test"]],{}]
[TRACE] JSON Recv: Token: 1, JSON: {"t":1,"r":[{"config_changes":[{"new_val":null,"old_val":{"db":"test","durability":"hard","id":"c58274be-c560-4127-8f3e-13e32a598476","indexes":[],"name":"test","primary_key":"id","shards":[{"nonvoting_replicas":[],"primary_replica":"W7L_R90H7009_6gj","replicas":["W7L_R90H7009_6gj"]}],"write_acks":"majority"}}],"tables_dropped":1}]}

I'm using the 2.2.10 version of the driver against RethinkDB 2.3.1 on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions