Skip to content

Commit 08add66

Browse files
committed
Environment keys can contain empty values
Environment keys that contain no value, get populated with values taken from the environment not from the build phase but from running the command `up`. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
1 parent ff83c45 commit 08add66

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

compose/config/fields_schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"type": "object",
4242
"patternProperties": {
4343
"^[^-]+$": {
44-
"type": ["string", "number", "boolean"],
44+
"type": ["string", "number", "boolean", "null"],
4545
"format": "environment"
4646
}
4747
},

compose/config/validation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _parse_valid_types_from_validator(validator):
143143
if len(validator) >= 2:
144144
first_type = anglicize_validator(validator[0])
145145
last_type = anglicize_validator(validator[-1])
146-
types_from_validator = "{}".format(", ".join([first_type] + validator[1:-1]))
146+
types_from_validator = ", ".join([first_type] + validator[1:-1])
147147

148148
msg = "{} or {}".format(
149149
types_from_validator,

tests/unit/config/config_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,23 @@ def test_invalid_interpolation(self):
414414
self.assertIn('in service "web"', cm.exception.msg)
415415
self.assertIn('"${"', cm.exception.msg)
416416

417+
def test_empty_environment_key_allowed(self):
418+
service_dict = config.load(
419+
build_config_details(
420+
{
421+
'web': {
422+
'build': '.',
423+
'environment': {
424+
'POSTGRES_PASSWORD': ''
425+
},
426+
},
427+
},
428+
'.',
429+
None,
430+
)
431+
)[0]
432+
self.assertEquals(service_dict['environment']['POSTGRES_PASSWORD'], '')
433+
417434

418435
class VolumeConfigTest(unittest.TestCase):
419436
def test_no_binding(self):

0 commit comments

Comments
 (0)