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

DateTime issues in Update function #49

Closed
alf opened this issue May 10, 2016 · 1 comment
Closed

DateTime issues in Update function #49

alf opened this issue May 10, 2016 · 1 comment
Labels

Comments

@alf
Copy link

alf commented May 10, 2016

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.

@bchavez
Copy link
Owner

bchavez commented May 11, 2016

2.3.1-beta-2 should now support this scenario. All DateTime types are now using ReqlDateTimeConverter pseudo types. Please be aware, though, any ReQL date/time functions like .Year will fail with dates that are outside the natively RethinkDB server supported range.

I would still recommend using nullable types and null conditional operators for date/times that have not been set.

https://www.nuget.org/packages/RethinkDb.Driver/2.3.1-beta-2

Thanks,
Brian

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

2 participants