-
Notifications
You must be signed in to change notification settings - Fork 2.1k
int64 IDs #597
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
Comments
I totally agree. Absolutely. |
I've noticed that too. By now, there are definitely some IDs that exceed the capacity of https://github.com/api/events The first event I got from a query just now was: {
"id": "5510765310",
"type": "WatchEvent",
"actor": {
"id": 12230841,
},
"repo": {
"id": 76620213,
},
"payload": {
"action": "started"
},
"public": true,
"created_at": "2017-03-17T01:19:24Z"
} The ID of that event exceeds 2^31 - 1. So far we've been using
SGTM. |
Actually, that's not a great example because https://godoc.org/github.com/google/go-github/github#Event.ID type is string, not int. |
The fact that both events and notifications (types of objects that are very likely to have IDs surpass 2 billion) encode their IDs as JSON strings rather than JSON numbers suggests that other IDs may be much smaller.
I've looked, and couldn't find anything either. But this is something that's important for the API docs to specify. Perhaps it'd be useful to send GitHub support an email to inquire about this. If they can assure us that those IDs are guaranteed to fit into int32, we won't have to make a change now. If they can confirm that int32 may not be enough, we can feel better about making the change. |
It's a global ID, right? It's not an ID scoped to just a single org or repo, right? If so, we don't need their confirmation. 2 billion is too small.
That is its own question. Why is it a string and not some integer type? Can it actually be non-numeric? |
Which ID are you talking about? As far as I know, different types of objects have different ID namespaces. There are IDs for users, repositories, events, notifications, gists (these are non-numbers), installations, etc. I'm sure that at least the user and repo IDs are separate namespaces (so may share equal IDs; here is user with ID 1, and here's repo with ID 1), but not completely sure about the others.
The JSON object actually contains a JSON string, so it has to be decoded into a We could consider the "string" option that
But then we'd need to be very confident it would always work (not contain non-numeric characters, and not overflow Both
It doesn't seem that way. I find it somewhat hard to feel confident if GitHub API docs don't actually specify this. On the other hand, Gist IDs are non-numeric, and it's clear from examples. |
I didn't know (or don't know whether) there is an ID namespace per resource type. But that also doesn't change my point. That just gives us ~5x more headroom if so. If we're concerned about quoted integers versus not, we could make our own numeric ID type: type ID int64 ... that implements https://golang.org/pkg/encoding/json/#Unmarshaler and deals with string-quoted integers or non-integers and not work about ",string" or changes to the encoding over time. The accessor methods could return For Gists or other hashes-as-IDs, I'd just keep it as "ID *string". |
Relevant issue (in a theoretical discussion sense, not practical one): |
There is no agreement at this time. We're waiting on someone to run into a concrete issue before we can decide how to act on this. So far, there have not been any issue reports, so it's better to wait. Go 2 might change Also, see what I wrote in #733 (comment) relatively recently:
|
Makes sense! Thanks for clearing, @shurcooL |
A relevant comment from GitHub Staff at https://platform.github.community/t/a-few-issues-ive-had-with-the-projects-preview-api/531/3:
That, to me, supports the idea that we don't need to act preemptively at this time, and waiting is a sound strategy. |
We've had a report of this issue causing real errors in production on a 32-bit architecture in #806. /cc @maruel It had to do with |
In the light of the recent crash report, are we actively interested in migrating all the In continuation of the same comment from GitHub Staff as linked above,
Also, shouldn't cc @shurcooL |
@kshitij10496 Are you using
I had the same thought. That's one of the options we should consider (and why I didn't want to accept PR #807 before discussing all the options in here first). |
My vote against |
@shurcooL I thank you for your concern. Currently, all my systems are 64-bit architecture so this doesn't directly affect me. (I did figure the implications of this issue after reading this thread and the external resources linked to it.) I thought of addressing the unsigned numeric
Thanks @maruel for this great advice. I will make a note of it for future references.
|
Go style is to use signed integers by default. Use of unsigned is reserved for bizarre cases when it's absolutely required. Some examples of Go using signed:
|
That makes sense in situations where the integer is often manipulated (and therefore, may end up being negative, even if it can never start out negative). That's the best reason I know why the builtin for i := len(s) - 1; i >= 0; i-- {
// use s[i]
} I'm not sure if the same rationale applies to IDs, since as I understand, they're not expected to be manipulated (by adding, subtracting amounts). They're only assigned or copied. So using an unsigned type can be acceptable. For completeness, some examples of Go using unsigned ints (where it's appropriate):
|
Sure. I wouldn't object to uint64 in this case if it's required. But I would be very surprised if GitHub uses the high bit of those 64-bit IDs, as that would be painful for their Java and JavaScript users. |
Talked this through with @gmlewis a bit, and both of us are having a hard time forming a strong opinion either way on signed versus unsigned int64. I think @bradfitz is right that it is very unlikely that GitHub ever uses the high bit, and my gut tells me that signed int64 would me slightly easier to work with, since I suspect that's what people are using in other backends, and so will result in less casting. So let's migrate all of these IDs to I'll try and get #772 resolved and submitted, so we've got proper versioning in place before this lands. But someone can go ahead and start the work on it. |
That seems gross and unnecessary. Also, App Engine supports Go 1.8 now, so even that existing hack should be deleted. |
After thinking about the alternatives, I'm convinced. Changing the ID fields from |
Thanks, @bradfitz for the guideline on the conventional use of numbers. I'm sure this will come in handy for me in the future. There are two considerations that I would like to make with regards to the migration of ID fields from
I can give this a try if no one has already started working on it. Here is a list of all the fields which correspond to GitHub IDs. This can act as an exhaustive, lookup reference while updating the methods which deal with IDs of particular structs as parameters. Some of them are referred as strings which we can ignore. However, I thought of mentioning them as well for the sake of completeness.
|
In this commit, the complete migration of all the struct IDs(which refer to GitHub IDs) from platform dependent `int` type to the signed `int64` takes place. A helper function "Int64" is also implemented to assist the migration of unit tests. Refer google#597
In this commit, the complete migration of all the struct IDs(which refer to GitHub IDs) from platform dependent `int` type to the signed `int64` takes place. A helper function "Int64" is also implemented to assist the migration of unit tests. Refer google#597
In this commit, the complete migration of all the struct IDs(which refer to GitHub IDs) from platform dependent `int` type to the signed `int64` takes place. A helper function "Int64" is also implemented to assist the migration of unit tests. Refer google#597
Edited the table above to add these fields that were missing in the table but present in PR #816 (and they're valid ID fields):
|
In this commit, the complete migration of all the struct IDs(which refer to GitHub IDs) from platform dependent `int` type to the signed `int64` takes place. A helper function "Int64" is also implemented to assist the migration of unit tests. Refer google#597
A helper function "Int64" is also implemented to assist the migration of unit tests. Refer #597.
Resolved via #816, closing. |
This is a breaking API change that is a part of issue #597. It should've been applied earlier, but we missed it because the parameter was misleadingly named number rather than id or commentID. Rename the parameter to commentID to make it more clear that it's the comment ID and not the PR ID nor PR number. This should help improve clarity of the API, and reduce the chance to mix up the IDs. Also document which PullRequestComment fields need to be set in EditComment method. Similar to #886. Updates #885. Updates #597.
When editing a comment, the current code used the issue number in place of the comment ID. But the EditComment endpoint needs the comment ID. The issue number is not needed at all in updateGithubComment because the EditComment endpoint uses the repository and comment ID to uniquely identify the comment. References: - https://developer.github.com/v3/issues/comments/#edit-a-comment. - https://godoc.org/github.com/google/go-github/github#IssuesService.EditComment. Updates golang/go#24598. Updates google/go-github#883. Updates google/go-github#597. Change-Id: Iae9d967d7be7a75b1bcee7118a3c80fe8f2375b4 Reviewed-on: https://go-review.googlesource.com/103398 Reviewed-by: Brad Fitzpatrick <[email protected]>
…888) This is a breaking API change that is a part of issue #597. It should've been applied earlier, but we missed it because the parameter was misleadingly named number rather than id or commentID. Rename the parameter to commentID to make it more clear that it's the comment ID and not the PR ID nor PR number. This should help improve clarity of the API, and reduce the chance to mix up the IDs. Also document which PullRequestComment fields need to be set in EditComment method. Similar to #886. Updates #885. Updates #597.
Field Since in OrganizationsListOptions refers to an organization ID, so its type needs to be int64 to per prior decision in #597. This is already the case in other similar structs such as RepositoryListAllOptions and UserListOptions. This is a breaking API change that is a part of resolving issue #597. It should've been applied earlier, but we missed it (likely because the field doesn't have "ID" in its name, so it's harder to spot). Updates #597.
A helper function "Int64" is also implemented to assist the migration of unit tests. Refer google#597.
…oogle#888) This is a breaking API change that is a part of issue google#597. It should've been applied earlier, but we missed it because the parameter was misleadingly named number rather than id or commentID. Rename the parameter to commentID to make it more clear that it's the comment ID and not the PR ID nor PR number. This should help improve clarity of the API, and reduce the chance to mix up the IDs. Also document which PullRequestComment fields need to be set in EditComment method. Similar to google#886. Updates google#885. Updates google#597.
Field Since in OrganizationsListOptions refers to an organization ID, so its type needs to be int64 to per prior decision in google#597. This is already the case in other similar structs such as RepositoryListAllOptions and UserListOptions. This is a breaking API change that is a part of resolving issue google#597. It should've been applied earlier, but we missed it (likely because the field doesn't have "ID" in its name, so it's harder to spot). Updates google#597.
This change makes ghinstallation consistent with github.com/google/go-github for App and Installation identifiers. See google/go-github#597 for related discussion. Fixes bradleyfalzon#27
This change makes ghinstallation consistent with `github.com/google/go-github` for App and Installation identifiers. See google/go-github#597 for related discussion. Fixes bradleyfalzon#27
On 32-bit platforms, a Go
int
is anint32
.I worry about the use of
int
as the type for Github IDs in the go-github package.Is there documentation to suggest that Github IDs are limited to 2 billion items? Seems unlikely. But I can't find anything.
I propose we keep "Number" fields as int, but change all the
ID
fields to beint64
.Thoughts?
/cc @gmlewis @willnorris @shurcooL
The text was updated successfully, but these errors were encountered: