-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
ORM: DeleteRange deletes entries with nil index fields #11980
Comments
Is this mainly about time stamps and durations? Not sure I totally understand what's happening here |
Yeah the bug was found with a timestamp index field, but i assumed it extend to any field that generates a pointer to a struct similar to timestamps/durations. basically, |
Yep, |
There is no explicit handling of |
I mostly was just not expecting it. I'd be curious how others feel about it before we try adding the extra. Maybe its just me 🤷🏻 If anything, some docs explaining this behavior would be good |
@technicallyty I'm thinking we should move forward with this and try to get it in soon. One question is should |
I'm thinking maybe nil time stamps should get sorted last. Is it safe to treat nil durations as 0? |
https://learnsql.com/blog/how-to-order-rows-with-nulls/ looks like theres not really a standard between db's, so either way is prob fine
that seems at odds with the proposed timestamp change tbh |
My thinking is that timestamps are often used for expiration so nil expiration means forever which would go at the end. Although I'm sure there's some counter-example where it's the opposite. For durations, I'm thinking that omitting a value is equivalent to saying 0. It would seem strange that nil durations go either at the beginning, before negative durations or at the end after the longest duration. If we were going to pick one order though, I would seem nil's at the beginning which is I guess okay but it would be strange if durations have nil's first and timestamps have nil's last. Also, we probably need to have special values of |
maybe we could add an option and just let the dev define ordering? something like |
I think that would be good to add in the future. I'd like to start with a sane default to begin with. Seems like nil duration as zero could be one of the options and maybe default |
Here's a proposed encoding that both handles Timestamp
Duration
|
Started working on a fix in #12273 |
In discussing this with @testinginprod, an alternative is to simply reject @ryanchristo I'm wondering if you're able to give some feedback as you're familiar with the case where this came up in practice. A variation of the encodings above could still be useful for reducing storage space, but that could be a separate issue. |
The specific issue we came across was with timestamps used for expiration. In our The workaround we implemented was to set the minimum range to The current workaround might be easier and more natural than expecting app developers to convert to the max acceptable value for timestamp. I don't have a strong preference and would be ok with leaving the workaround we currently have. |
Thanks @ryanchristo. Am I correct in assuming that with the current solution in #12273, that I wonder if there are any cases where we'd want |
I think |
I'm not sure whether the duration encoding proposed is quite what we want. It proposes that It seems like it might be better to do the same thing we do for timestamps and have Any thoughts @ryanchristo or @testinginprod ? |
If the decision for timestamp is to put nil at the end (and not to reject it), then we should apply it to duration too, for consistency. |
I agree. We should probably maintain consistency. |
I've updated the proposal to order |
Summary of Bug
Given a table that generates a pointer field, and creating an ORM index on that field:
Get
will fetch the object with the field as nilDeleteRange
with a 0'd value index, will delete any entry with the corresponding field asnil
Version
orm/v1.0.0-alpha.12 and all before
Steps to Reproduce
nil
DeleteRange
on the table with thefrom
as the default/zero value of the generated struct (your user defined message struct, or the corresponding import i.e.timestamppb.Timestamp{}
.For Admin Use
The text was updated successfully, but these errors were encountered: