Urgent.News

What's breaking now, across thousands of outlets.

Tech

Fixing the “D.map is not a function” crash by tightening DB indexes and normalizing the API payload

Fixing the “D.map is not a function” crash by tightening DB indexes and normalizing the API payload TL;DR: I added missing PostgreSQL indexes in apps/api/src/db/db.ts and forced the /condos/metrics endpoint to always return an array. The change stopped the runtime TypeError: D.map is not a function in the React selector and restored correct KPI calculations. The Problem Our internal “Condo…

The Condo Dashboard began experiencing a runtime error: TypeError: D.map is not a function. The error occurred in the React selector component when the dropdown was empty and the component crashed. The API call responsible for populating the dropdown (GET /api/condos/metrics) was supposed to return an array of objects with id and name properties, but under certain conditions, it returned null or a single object instead.

This inconsistency caused the .map call to fail, breaking the component. The root cause was discovered to be duplicate rows in the broker_tokens table, which resulted from missing unique indexes on several tables. These duplicates caused the query to return malformed results, leading to the error. Initially, the front-end attempted to mitigate the issue by checking if the data was an array before processing it.

However, this only temporarily silenced the error, as the API continued to return the incorrect data shape, leading to duplicate entries in downstream calculations. The KPI numbers in the dashboard remained inaccurate. To resolve the issue, a two-pronged approach was implemented. First, proper indexes were added to the database to prevent duplicate broker token rows and enforce referential integrity.

Second, the metrics endpoint was refactored to guarantee an array output, even if the result was empty. This ensured the front-end received the correct data format, effectively fixing the crash and restoring accurate KPI calculations. Additionally, a small guard was left in the CondoSelector component to handle any future API misbehavior.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Who is John Ternus, the new Apple CEO?

Starting on September 1, Ternus will lead one of the world's most valuable companies, but if you're not a dedicated Apple enthusiast, you've probably never heard of this man, who has largely remained…

Inside `oblien/openship`: A Practical Look at Self-Hosted Deployment Control

oblien/openship is gaining attention as a self-hosted deployment platform, with more than 111 new GitHub stars today. The interesting part is not the number itself; it is the operational model behind…

  • Oblien/openship offers self-hosted deployment control within private environments.
  • Platform simplifies private-network routing and reduces external control plane reliance.
  • Critical to assess deployment lifecycle alignment with team's release process.

I Built an Agent to Fix Bad Tests. I Found Eight Bugs in My Own Ruler.

Here is a Python function and a test for it. def withdraw ( balance , amount ): if amount <= 0 : raise ValueError ( " amount must be positive " ) if amount > balance : raise ValueError ( "…

  • Author built an agent for mutation testing to fix bad tests
  • Identified eight bugs in own measuring instrument
  • Bugs include handling editable installs and concurrency issues

Apple Teases 'Huge Launch' Next Week

In his first memo to Apple employees as CEO today, John Ternus teased a "huge launch next week that's going to be phenomenal." In a social media post today, Apple's marketing chief Greg Joswiak teased…

More from Tuesday 1 September →