Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your Next Coding Interview Might Start With Code You Didn’t Write

A practical debugging rehearsal: trace one request, isolate the mistake, and prove the repair without rewriting everything. You prepare to build a solution from an empty editor. Then you open the interview project and discover that the solution already exists. It just does not work. There are routes you did not name, a storage layer you did not choose, and a failing test whose description sounds…

Debugging code in a coding interview often involves analyzing existing code that does not work as intended. The key is to approach the problem methodically, focusing on one path of execution at a time. The goal is to determine where the code deviates from the expected behavior and make the smallest necessary change to correct it.

Consider a car-rental service where a user updates the daily price of a car. The initial update response shows the new price, but subsequent requests return the old price. To debug this issue, first write down the contract: an authenticated user should be able to update the price, and a subsequent read should reflect the change.

Start by tracing the code execution: request → authenticated user → handler → repository → stored record → response. The critical question is whether the stored record has changed. If the stored record still shows the old price, focus on the write operation. If the stored record shows the new price but the response does not, investigate the read operation.

The provided code example demonstrates a function that updates a car's price but only returns the updated object without modifying the actual store. This results in the store remaining unchanged despite the successful response. To address this, add a call to the repository's update method, which performs the actual update and returns the saved record. This ensures that the stored price is updated, and subsequent reads reflect the change.

The repair involves implementing an explicit update operation in the repository. This operation should match the car ID and owner ID, apply the validated changes, and return the updated record. By ensuring that the repository performs the write operation and returns the updated record, the endpoint can reliably return the correct price.

To prove the repair, perform a series of tests. Seed the system with a car owned by a user with a specific price. Change the price through the edit function and then read the car's price through the application's normal read path. Confirm that both the response and the stored record contain the updated price. Repeat the process as a different user to ensure that only the authorized user can make changes.

Additionally, test for failure scenarios. Attempt the edit as a different user and ensure that no change occurs. Simulate a storage write failure and verify that the endpoint does not return a successful message. Use the project's documented error contract to determine the appropriate status codes for these error conditions.

By following this systematic approach, you can identify the root cause of the issue, implement a targeted fix, and validate the repair through comprehensive testing. This process not only helps you understand the existing code but also builds a robust solution that meets the contract requirements.

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

Hybrid Cloud Security: The Gaps Nobody Talks About Until It's Too Late

Most organisations don’t move to the cloud in one clean jump. They end up with a foot in both worlds: some systems on-premises, some in Azure or AWS, and a lot of plumbing connecting the two.

  • Hybrid cloud environments hide most security risks due to oversight.
  • Identity seam connects on-premises AD with cloud identity provider, risking breach propagation.
  • Regular reviews, automation, and clear responsibilities are key to mitigating hybrid security gaps.

Hyperbolic tiling in Python: draw Escher's Poincare disc and 3D print it

Escher's Circle Limit prints show a hyperbolic tiling squeezed into a disc, with tiles shrinking toward the rim. The maths is short: a tile edge is a circle that meets the unit circle at right angles…

  • Escher's Circle Limit prints illustrate hyperbolic tiling within a disc.
  • {7,3} tiling involves heptagons with three at each corner.
  • 3D print ornament using manifold3d with specified parameters.

SSRF on a media server: the cloud instance case

SSRF on a media server: the cloud instance case A media server in a living room and the same software in a cloud virtual machine are not the same risk.

  • SSRF vulnerability in Plex Media Server affects cloud instances.
  • Attackers target instance metadata service for credentials and config data.
  • Cloud providers' defenses do not render the endpoint irrelevant.

More from Friday 23 October →