It happened to a friend who wasn't passing in the proper types into their stored procedures, all strings, and "null" (not case sensitive) conflicted with actual null values. Everything in the web interface were strings, and so was null.
For some people it takes this mistake before they learn to always care about the data types you're passing in.
With LLM coding increasing, it might be going up. Idk am no pro, just worried.
Tangential, but I find it hilarious how Gemini's syntax fucks up all the time.
I ask it to change my light called "CX2" to red. It complies, like usual, and it reads Okay, changing "CX2" to red., but what it says out loud is Okay, changing "CX two inches to red.
As a backbend dev, I blame DBAs. We were forced to support CSV imports from out support team so they could fix data issues on their own, and now we have some wonky data in prod...
Input sanitization typically handles this as a string that only allows characters supported by the data type specified by the table field in question. A permissive strategy might scrub the string of unexpected characters. A strict one might throw an error. The point, however, is to prevent the evaluation of inputs as anything other than their intended type, whether or not reserved characters are present.
It's baffling to me. Maybe I'm just used to using "modern" frameworks, but the only way this could be an issue is if you literally check if the string value equals "null" and then replace it with a null value.
COPY user_data (id, last_name)
FROM '/path/to/data.csv'
WITH (FORMAT csv, HEADER true);
number 5 will be imported as a string "NULL" but number 3 will be imported as a NULL value. of course, this is why you sanitize the data (GIGO) but I can imagine this happening countless times at companies all over the country
there are easy fixes if you're paying attention
COPY user_data (id, last_name)
FROM '/path/to/data.csv'
WITH (FORMAT csv, HEADER true, NULL '');
sets the empty string to NULL value.
example with js
fetch('/api/user/1')
.then(response => response.json())
.then(data => {
if (data.lastName == "null") {
console.log("No last name found");
} else {
console.log("Last name is:", data.lastName);
}
});
if data is
data = {
id: 5,
lastName: "null"
};
then the if statement will trigger- as if there was no last name. that's why you gotta know the language you're using and the potential pitfalls
now you may ask -- why not just do
if (data.lastName === null)
instead? But what if the system you're working on uses JSON.parse(data) and that auto-converts everything to a string? it's a very natural move to check for the string "null"
obviously if you're paying attention and understand the pitfalls of certain languages (like javascript's type coercion and the particularities of JSON.parse()) it becomes easy but it's something that is honestly very easy to overlook
Like you said, GIGO, but I can't say I'm familiar with any csv looking like that. Maybe I'm living a lucky life, but true null would generally be an empty string, which of course would still be less than ideal. From a general csv perspective, NULL without quotes is still a string.
If "NULL" string, then lord help us, but I would be inclined to handle it as defined unless instructed otherwise. I guess it's up to the dev to point it out and not everyone cares enough to do so. My point is these things should be caught early.
I'll admit I'm much more versed in mysql than postgres.
I have never seen this happen, and I don't know what tools would confuse the strings "null" or "Null" with NULL. From the comments in this thread, there are evidently more terribly programmed systems than I imagined.
Yep. For the curious, any time a license plate photo couldn’t be fully read by the automated system, it was marked as “NULL” and he was flagged as the driver. So every single red light camera and speeding camera in the area was sending him to court every day.
There is an infosec guy in California who had NULL as his car license plate. If a license-plate reader detects a ticketable event but the license plate is unreadable, guess how the system handles those events?