Code Monkey home page Code Monkey logo

Comments (9)

timshannon avatar timshannon commented on July 22, 2024 1

Yeah that would work as a workaround, but I think I'm going to change the behavior to ensure a byte compare happens when using the bolthold.Key field.

from bolthold.

timshannon avatar timshannon commented on July 22, 2024

That is interesting, and it looks like a bug. What UUID package are you using, and what encoding? My guess is that with Get it's doing a strict byte comparison, where as Find attempts to make a comparison and may end up doing a UUID.String() comparison.

from bolthold.

voroskoi avatar voroskoi commented on July 22, 2024

Hi,

The UUID package is "github.com/google/uuid". I will try adding a Comparer to see if that helps.

Thanks,

from bolthold.

timshannon avatar timshannon commented on July 22, 2024

Sorry it's taken so long, but I finally found some time to look at this, and I'm having trouble replicating the issue.

Here's my attempt a repro which passes fine. I expected it to fail

func Test126FindOneVSGetOne(t *testing.T) {
        testWrap(t, func(store *bolthold.Store, t *testing.T) {
                type Test struct {
                        UUID uuid.UUID
                }

                id := uuid.New()

                store.Upsert(id, Test{UUID: id})

                result := Test{}
                ok(t, store.FindOne(&result, bolthold.Where(bolthold.Key).Eq(id)))
                equals(t, result.UUID, id)

                result = Test{}
                ok(t, store.Get(id, &result))
                equals(t, result.UUID, id)

        })
}

Could you show me how you are inserting the data and generating the UUID?

from bolthold.

voroskoi avatar voroskoi commented on July 22, 2024

Hi,

Thanks for Your time! I went on with using string instead of uuid.UUID as a workaround, but I am still curious what is going on here.

Your test works indeed, I have also tried to write my own reproducer so I can avoid the walk of shame comes with showing my real code, but I guess I can not help it.

These functions are for adding and getting a ShiftLogEntry:
https://git.sr.ht/~voroskoi/nRG/tree/ce0c37e08ab5f2ba6b62aa4c16cada480762e546/item/internal/db/sle.go

And these are the handler functions:
https://git.sr.ht/~voroskoi/nRG/tree/ce0c37e08ab5f2ba6b62aa4c16cada480762e546/item/internal/ui/sle.go

The error occurs on line 71. If I use the commented out line in SLEGet function it works, when I try using Get directly it does not.

Funny thing that after adding new entries getting them works for a while, but I have items that used to work, but now they do not. I have spent couple of hours to find out what happens, but I can not even reproduce it :-(

from bolthold.

timshannon avatar timshannon commented on July 22, 2024

So I may be wrong, as I've only done quick look through of your code, but I believe the issue is that you are defining your Key as a string here: https://git.sr.ht/~voroskoi/nRG/tree/master/item/models/shiftlog.go#L17

but trying to get it with a UUID type here: https://git.sr.ht/~voroskoi/nRG/tree/ce0c37e08ab5f2ba6b62aa4c16cada480762e546/item/internal/db/sle.go#L30

So the Find query just happens to work in this scenario because it's changing the UUID type to string because it can't find any other way to compare these two different types, and it works because you are actually storing the UUID as a string.

from bolthold.

voroskoi avatar voroskoi commented on July 22, 2024

No, it is not that. On Mar 18 I was at this state:
https://git.sr.ht/~voroskoi/nRG/tree/ce0c37e08ab5f2ba6b62aa4c16cada480762e546/item/models/shiftlog.go#L25

So You have mixed git HEAD with ce0c37e08ab5f2ba6b62aa4c16cada480762e546, I have switched to string with the next commit as I was unable to figure out what is going on.

from bolthold.

timshannon avatar timshannon commented on July 22, 2024

So once again, I can't replicate this issue myself. If you can get me a stand alone piece of code to replicate this, then I'll have something to fix, otherwise I don't see any issues here.

from bolthold.

voroskoi avatar voroskoi commented on July 22, 2024

I have written a minimal version of my program with inserting to the db and retrieving values via a http.Hander, but I was unable to reproduce this problem.

I think there are some other issue with the original code, which I can not reproduce and probably not related to bolthold.

from bolthold.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.