diff --git a/compose/config/config.py b/compose/config/config.py index 659b6cd59..cb25a25a6 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -571,7 +571,7 @@ class ServiceExtendsResolver(object): config_path = self.get_extended_config_path(extends) service_name = extends['service'] - if config_path == self.service_config.filename: + if config_path == self.config_file.filename: try: service_config = self.config_file.get_service(service_name) except KeyError: diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 63cb7eaef..fd06db7d1 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -702,6 +702,42 @@ class ConfigTest(unittest.TestCase): ] self.assertEqual(service_sort(service_dicts), service_sort(expected)) + def test_load_mixed_extends_resolution(self): + main_file = config.ConfigFile( + 'main.yml', { + 'version': '2.2', + 'services': { + 'prodweb': { + 'extends': { + 'service': 'web', + 'file': 'base.yml' + }, + 'environment': {'PROD': 'true'}, + }, + }, + } + ) + + tmpdir = pytest.ensuretemp('config_test') + self.addCleanup(tmpdir.remove) + tmpdir.join('base.yml').write(""" + version: '2.2' + services: + base: + image: base + web: + extends: base + """) + + details = config.ConfigDetails('.', [main_file]) + with tmpdir.as_cwd(): + service_dicts = config.load(details).services + assert service_dicts[0] == { + 'name': 'prodweb', + 'image': 'base', + 'environment': {'PROD': 'true'}, + } + def test_load_with_multiple_files_and_invalid_override(self): base_file = config.ConfigFile( 'base.yaml',