惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
月光博客
月光博客
S
SegmentFault 最新的问题
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI

Anže's Blog

The 15-Year-Old iptables Rule That Broke My DNS Fedidevs 9h Outage Postmortem Letting Claude Upgrade My Raspberry Pi Agents Day Lisbon DjangoCon Europe 2026 How to Safely Update Your Dependencies Speeding Up Django Startup Times with Lazy Imports Typing Your Django Project in 2026 Claude Fixes User Bug Jekyll to Hugo Migration Advent of Code 2025 🎄 Django bulk_update Memory Issue Migrating Gunicorn to Granian Disable Network Requests When Running Pytest Disable Runserver Warning in Django 5.2 Autogenerating og:images with Jekyll Power Outages and Gunicorn PID Files UV with Django Go-like Error Handling Makes No Sense in JavaScript or Python Packages Do Not Match the Hashes Pip Error Gotchas with SQLite in Production Fedidevs Dev Update #2 Django SQLite Production Config Django Streaming HTTP Responses Deploying a Django Project to My Raspberry Pi (Video) Thoughts on Code Reviews Django SQLite Benchmark Django, SQLite, and the Database Is Locked Error No Downtime Deployments with Gunicorn SQLite Write-Ahead Logging
Integer Overflow Error in a Python Application
Anže Pečar · 2022-07-02 · via Anže's Blog

A Sentry error popped up that looked very suspicious.

Exception stack trace with KeyError -24212

It piqued my interest for two reasons:

  1. Customers were getting upset about it.
  2. The value -24212 was supposed to be a primary key and those tend to be greater than 0.

Something very fishy was going on, so I immediately went and checked if MySQL was to blame:

SELECT * FROM boring_table WHERE id < 0

No results. Can’t blame MySQL for this one.

A wildly incorrect integer value can sometimes result from of an Integer Overflow. Integer Overflow happens when the integer field does not have enough bits to store the value. Part of the bits gets clipped, producing a result that is very much unlike the value we were trying to store.

In Python, Integer Overflows aren’t common. In fact, since PEP-0237 landed in Python 2.2 they became impossible. Python’s integers will continue increasing (or decreasing) without issues until they run out of system memory.

So the Sentry error made no sense, but thanks to my untrusting nature, I decided to walk through the codebase and see what we were doing with boring_group_id. A couple of functions up the stack, I found this code:

return (
    pd.concat(
        [
            query_result["BORING_GROUP_ID"],
            query_result["PARENT_BORING_GROUP_ID"],
        ]
    )
    .dropna()
    .astype("int16")
    .unique()
)

Looks like those ids were going through a pandas dataframe where invalid values and duplicates were dropped. For some reason, we were also casting the values to 16-bit integers. Because of this, the function was returning incorrect values for any id greater than 32_767.

Changing the line to .astype("int64") resolved the issue and the problem will only pop up again when ids become greater than 9_223_372_036_854_775_807 at which point I should be long gone.

We pushed the fix to production and made the customers happy, or at least a little less upset. 🎉