-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: delete process.env values set to undefined #18158
Conversation
40e3915
to
6c63403
Compare
src/node.cc
Outdated
@@ -2715,6 +2715,18 @@ static void EnvGetter(Local<Name> property, | |||
static void EnvSetter(Local<Name> property, | |||
Local<Value> value, | |||
const PropertyCallbackInfo<Value>& info) { | |||
if (value->IsUndefined()) { | |||
#ifdef __POSIX__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use EnvDeleter()
instead of duplicating the code?
@cjihrig Not sure how. Two things to consider:
I pushed a change to move the code to another function, PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT - Removed my approval as I don't feel strongly enough that this should land given the objections.
doc/api/process.md
Outdated
@@ -899,6 +904,10 @@ process.env.TEST = 1; | |||
delete process.env.TEST; | |||
console.log(process.env.TEST); | |||
// => undefined | |||
process.env.TEST = 1; | |||
process.env.TEST = undefined; | |||
console.log(process.env.TEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, would it be better to show that the property TEST
doesn't exist anymore in process.env
, like in the test? As it is, it may not convey the idea clearly (setting undefined
and then undefined
is printed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this?
console.log('TEST' in process.env);
// => false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's better, right?
Before this commit, setting a property of process.env to undefined would set the value to the string "undefined". This changes the behavior to instead remove the value, working like the delete operator. Refs: nodejs#15089
f49e58d
to
f88476a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if this is semver-major, I still think this behavioral change is too significant to be done on process.env
, especially when we previously documented to do the contrary. Plus, as #16961 demonstrated, we can never have a truly Correct environmental variable implementation with a string-based API. My opinion for this is, instead of adding exceptions to a previously internally consistent class, we should just leave process.env
alone.
The current behavior is not without precedent either. The Web Storage API (better known as Local Storage and Session Storage) also cast undefined
to string.
I'm adding this to the next TSC agenda. |
Setting What about other non-string values? Shouldn't this throw or something?
What about |
I'm torn on this one because I really like the idea of deleting but setting to |
I agree with @TimothyGu and I am also -1 on this. |
This was discussed at the last TSC meeting. We are going to invite Timothy to this week's meeting and then call for a vote. |
I like this, but without being able to attend to hear discussion I'll register an abstention for now unless it comes back for a vote. |
Discussed in TSC meeting today. Still differing views, lets see if we can get Timothy at the next meeting before having a vote. |
I'm pretty much in the same boat as @addaleax. I think it should have worked like this from the start. If this PR doesn't land, I wouldn't be too upset though. |
I don't feel strongly for this to land, although the comment in #18158 (comment) should be addressed
It feels even stranger if we treat null and undefined differently. |
Don't feel strongly that this should land at this point given the objections
+1, better late than never. It is fair for a end user to expect
rather than
because that is how normal objects behave:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@gireeshpunathil Your argument is one with a slippery slope. What makes We should instead focus on creating a better API in general that allows us to tackle #16961, rather than retrofitting suboptimal designs onto an object that has wide-spread compatibility impact. |
nothing, I don't discriminate null vs. undefined in this case - isn't it straightforward to fix
Existence of other, larger problem to be solved need not be a consideration for solving a problem for which fix is easy, right?
generally agree, but again, issue reported in #16961 need not hinder this from progressing, and both of them are not exclusive IMO. |
@TimothyGu - on a second thought, I don't believe this will have a wide-spread compatibility impact. Can you explain potential implications of this change in the field? |
@TimothyGu I’m in the “not too sad if this doesn’t happen” bucket, but I’m going to point out that many people (esp. language beginners) think of missing properties and properties with an |
Are you proposing a new API to improve the situation? I'm not sure that will help. A lot of modules rely on I think we are not providing a good experience to anyone relying on Side note, I think we might even throw if you are setting an object. |
@mcollina A separate API is what is being suggested in #16961, although for a completely different reason. |
This is not true. I am not opposed to moving away from |
I can look into this. Don't know if this is actually possible because AFAIK process.env is not really an object but a sort of C++ proxy acting like one. |
Hmmm, well it's mostly just a preference, |
@Fishrock123 What would be stored in the actual environment in that case? |
Now that is something I can get behind, and I believe that is better than both this PR and the status quo. And in fact I think we can and should start with documentation-only deprecation of setting non-string to The compatibility impact is difficult to measure however. @ChALkeR ;)
I see what you are saying. However, I'd like to contend that this PR doesn't help with the general issue of making Even worse, I understand that a lot of Node.js developers come from other JavaScript-based platforms, like the browser world, where For that reason, I believe throwing an error when setting non-string to
That would be even odder given the current behavior and implementation of
The point is that the impact will for sure be non-zero. And this, coupled with other disadvantages I pointed out before, forms the body of my objection. |
I'm definitely 👍 on this approach. If you are setting |
I have proposed my approach to this issue in #18990. |
I think this can be closed in favor of #18990. |
No objection to closing from me. |
PR-URL: #18990 Refs: #15089 Refs: #18158 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
PR-URL: nodejs#18990 Refs: nodejs#15089 Refs: nodejs#18158 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Before this commit, setting a property of process.env to undefined
would set the value to the string "undefined". This changes the
behavior to instead remove the value, working like the delete operator.
Refs: #15089
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
process