# Error: integer out of range

**URL:** https://meta.discourse.org/t/error-integer-out-of-range/200619
**Category:** Bug
**Created:** [August 16, 2021, 4:35pm UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619 "2021-08-16T16:35:24Z")
**Posts on this page:** 9
**Page:** 2

<div class="post-metadata">

### Author: ![bjlarouche](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bjlarouche/32/240230_2.png) [@bjlarouche](https://meta.discourse.org/u/bjlarouche)
#### Post date: [February 15, 2023, 6:12pm UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/22 "2023-02-15T18:12:52Z")

</div>

This did the trick for post\_actions, thanks for the suggestion!

We’re mainly now seeing two failures still:

1. `GET https://devforum.roblox.com/notifications` is 404ing for users who have notifications w/ bigInt ids.

2. Jobs::GrantAnniversaryBadges scheduled job fails

_Is it possible that a notifications model/controller/service could still be hardcoded to define the `notifications.id` field as an integer?_

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 16, 2023, 12:16am UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/23 "2023-02-16T00:16:55Z")

</div>

> [@bjlarouche](#):
>
> Is it possible that a notifications model/controller/service could still be hardcoded to define the `notifications.id` field as an integer?

very unlikely … 404 does not sound right, is there anything in `/logs` that describes the problem?

---

<div class="post-metadata">

### Author: ![bjlarouche](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bjlarouche/32/240230_2.png) [@bjlarouche](https://meta.discourse.org/u/bjlarouche)
#### Post date: [February 16, 2023, 1:19am UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/24 "2023-02-16T01:19:52Z")

</div>

Sadly I can’t find anything particularly useful in /logs itself, but when I reproduce this locally I see the req come in and then 404, but it only happens when I set my latest notification to have an id that is a bigint (works just fine when its within int32 range)

 ![Screen Shot 2023-02-15 at 4.55.36 PM](https://global.discourse-cdn.com/meta/original/4X/6/7/b/67b246d0a421a6c429228906963f8b12164cd220.png)

Poking around, I notice that I get a valid response when I call `http://localhost/notifications.json?limit=30`:

```json
{
  "notifications": [
    {
      "id": 2148935910,
      "user_id": 2,
      "notification_type": 5,
      "read": true,
      "high_priority": false,
      "created_at": "2023-02-16T00:50:53.135Z",
      "post_number": 2,
      "topic_id": 8,
      "fancy_title": "Welcome to the Lounge",
      "slug": "welcome-to-the-lounge",
      "data": {
        "topic_title": "Welcome to the Lounge",
        "original_post_id": 13,
        "original_post_type": 1,
        "original_username": "blarouche",
        "revision_number": null,
        "display_username": "blarouche"
      }
    }
  ],
  "total_rows_notifications": 1,
  "seen_notification_id": 1001,
  "load_more_notifications": "/notifications?offset=60&username=bjlarouche"
}

```

However, once I pass the `recent` query param i.e `http://localhost/notifications.json?recent=true&limit=30` and this is what’s called my the notification menu?

```json
{
  "errors": [
    "The requested URL or resource could not be found."
  ],
  "error_type": "not_found"
}

```

 ![Screen Shot 2023-02-15 at 5.18.19 PM](https://global.discourse-cdn.com/meta/original/4X/b/b/3/bb336dba8f179305130a42ff0796632b28f106cf.png)

_edit: we are thinking it its that is because of the [current\_user.seen\_notification\_id](https://github.com/discourse/discourse/blob/main/app/controllers/notifications_controller.rb#L65) is still and integer 🤔_

---

<div class="post-metadata">

### Author: ![bjlarouche](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bjlarouche/32/240230_2.png) [@bjlarouche](https://meta.discourse.org/u/bjlarouche)
#### Post date: [February 16, 2023, 8:01pm UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/26 "2023-02-16T20:01:47Z")

</div>

I think we are now in the clear!

We noticed that we needed to migrate columns in other tables that referenced notification\_id in addition to just notifications.id itself. Othwerwise, `services/notifications.rb` or `services/badge_granter.rb` would throw errors.

* * *

For any other **big** forum setup who runs into this in the future with notifications, here is what we did…

All together, we had to migrate four columns in four tables:

1. `notifications.id`
2. `user.seen_notification_id`
3. `user_badges.notification_id`
4. `shelved_notifications.notification_id`

We initially went about #1 with the ALTER command suggested above, but then as mentioned opted to use ActiveRecord migrations, that way the migration files add up to the schema.

> **20230215070319\_change\_notifications\_id\_to\_bigint.rb**
>
> ```rb
> # frozen_string_literal: true
> 
> class ChangeNotificationsIdToBigint < ActiveRecord::Migration[6.1]
> def change
> change_column :notifications, :id, :bigint
> end
> end
> 
> ```

> **20230215070320\_change\_user\_seen\_notification\_id\_to\_bigint.rb**
>
> ```rb
> # frozen_string_literal: true
> 
> class ChangeUserSeenNotificationIdToBigint < ActiveRecord::Migration[6.1]
> def change
> change_column :users, :seen_notification_id, :bigint
> end
> end
> 
> ```

> **20230215070321\_change\_user\_badges\_notification\_id\_to\_bigint.rb**
>
> ```rb
> # frozen_string_literal: true
> 
> class ChangeUserBadgesNotificationIdToBigint < ActiveRecord::Migration[6.1]
> def change
> change_column :user_badges, :notification_id, :bigint
> end
> end
> 
> ```

> **20230215070322\_change\_shelved\_notifications\_notification\_id\_to\_bigint.rb**
>
> ```rb
> # frozen_string_literal: true
> 
> class ChangeShelvedNotificationsNotificationIdToBigint < ActiveRecord::Migration[6.1]
> def change
> change_column :shelved_notifications, :notification_id, :bigint
> end
> end
> 
> ```

We have a custom Dockerfile in our setup (we build images so that we can run discourse and sidekiq on separate resouces in Kubernetes) so getting these files copied into `/db/migrate` as part of our Dockerfile was straightforward.

Then, we just let `rake db:migrate` handle the rest. Once we did a rolling restart on all of our discourse and sidekiq pods everything was running as expected 🤞.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 16, 2023, 11:11pm UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/27 "2023-02-16T23:11:27Z")

</div>

> [@bjlarouche](#):
>
> All together, we had to migrate four columns in four tables:
> 
> 1. `notifications.id`
> 2. `user.seen_notification_id`
> 3. `user_badges.notification_id`
> 4. `shelved_notifications.notification_id`

Excellent data, we are going to just bite the bullet and migrate this in core discourse to a bigint. It is an expensive move , but this will certainly pop up again on big forums so we might as well fix it.

Note … the OP is about post\_id … overflowing that going to be a lot harder than notifications. 2.1 billion posts certainly going to happen, but the cost of biginting post\_id is far more expansive than notification id. We can wait a bit on that time bomb.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 2, 2023, 5:23am UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/28 "2023-03-02T05:23:35Z")

</div>

Brandon,

I think we may end up going with:

[https://github.com/discourse/discourse/pull/20505/files](https://github.com/discourse/discourse/pull/20505/files)

The balancing act here is that I don’t want to “punish” 40k Discourse instances because of the one or two outlier forums that managed to reach the amazing feat of 2.5 billion notifications.

What do you think?

(Note: It will also catch at least one you missed - there is a chat table as well)

---

<div class="post-metadata">

### Author: ![markersocial](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markersocial/32/170136_2.png) [@markersocial](https://meta.discourse.org/u/markersocial)
#### Post date: [April 25, 2023, 8:44am UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/29 "2023-04-25T08:44:29Z")

</div>

This would be great and looks like a smart solution 🙂

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 21, 2023, 2:42pm UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/33 "2023-06-21T14:42:28Z")

</div>

Just to loop back here - this has now been merged. 🥳

[https://github.com/discourse/discourse/pull/20505/files](https://github.com/discourse/discourse/pull/20505/files)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 26, 2023, 7:00am UTC](https://meta.discourse.org/t/error-integer-out-of-range/200619/34 "2023-06-26T07:00:20Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.

[Previous page](https://meta.discourse.org/t/error-integer-out-of-range/200619.md?page=1)
