# Buggy code
def prepare_field(cls, field: ModelField) -> None:
    env_names: Union[List[str], AbstractSet[str]]
    env = field.field_info.extra.get("env")
    if env is None:
        if field.has_alias:
            warnings.warn(
                "aliases are no longer used by BaseSettings to define which environment variables to read. "
                'Instead use the "env" field setting. '
                "See https://pydantic-docs.helpmanual.io/usage/settings/#environment-variable-names",
                FutureWarning,
            )
        env_names = {cls.env_prefix + field.name}
    elif isinstance(env, str):
        env_names = {env}
    elif isinstance(env, (set, frozenset)):
        env_names = env
    elif sequence_like(env):
        env_names = list(env)
    else:
        raise TypeError(
            f"invalid field env: {env!r} ({display_as_type(env)}); should be string, list or set"
        )

    if not cls.case_sensitive:
        env_names = env_names.__class__(n.lower() for n in env_names)
    field.field_info.extra["env_names"] = env_names


# Traceback (ValidationError)
In [2]: from pydantic import AnyUrl, BaseSettings
In [4]: %set_env FOO=7
env: FOO=7

In [9]: class A(BaseSettings):
...:     foo : int
...:     class Config:
...:         env_prefix = 'PREFIX_'
...:         fields = {
...:             'foo': {'env': ['FOO', 'PREFIX_FOO'],},
...:         }
...:
...:
In [10]: A().foo
Out[10]: 7

In [11]: A.__fields__['foo'].field_info
Out[11]: FieldInfo(default=Ellipsis, extra={'env': ['FOO', 'PREFIX_FOO'], 'env_names': ['foo', 'prefix_foo']})

In [12]: class A(BaseSettings):
...:     foo : int
...:

In [13]: class B(A):
...:     class Config:
...:         env_prefix = 'PREFIX_'
...:         fields = {
...:             'foo': {'env': ['FOO', 'PREFIX_FOO'],},
...:         }
...:
...:
...:

In [14]: B().foo
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-14-40329edc0228> in <module>
----> 1 B().foo
~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/env_settings.cpython-36m-x86_64-linux-gnu.so in pydantic.env_settings.BaseSettings.__init__()
~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/main.cpython-36m-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()
ValidationError: 1 validation error for B
foo
field required (type=value_error.missing)

In [15]: A.__fields__['foo']
Out[15]: ModelField(name='foo', type=int, required=True)

In [16]: A.__fields__['foo'].field_info
Out[16]: FieldInfo(default=Ellipsis, extra={'env_names': {'foo'}})

In [17]: B.__fields__['foo'].field_info
Out[17]: FieldInfo(default=Ellipsis, extra={'env_names': {'prefix_foo'}})

# Fixed code
def prepare_field(cls, field: ModelField) -> None:
    env_names: Union[List[str], AbstractSet[str]]
    field_info_from_config = cls.get_field_info(field.name)

    env = field_info_from_config.get("env") or field.field_info.extra.get("env")
    if env is None:
        if field.has_alias:
            warnings.warn(
                "aliases are no longer used by BaseSettings to define which environment variables to read. "
                'Instead use the "env" field setting. '
                "See https://pydantic-docs.helpmanual.io/usage/settings/#environment-variable-names",
                FutureWarning,
            )
        env_names = {cls.env_prefix + field.name}
    elif isinstance(env, str):
        env_names = {env}
    elif isinstance(env, (set, frozenset)):
        env_names = env
    elif sequence_like(env):
        env_names = list(env)
    else:
        raise TypeError(
            f"invalid field env: {env!r} ({display_as_type(env)}); should be string, list or set"
        )

    if not cls.case_sensitive:
        env_names = env_names.__class__(n.lower() for n in env_names)
    field.field_info.extra["env_names"] = env_names