Repository: apache/airflow

Issue:
[BUG] 2.4.0b1 - google-provider - AttributeError: 'str' object has no attribute 'version'
### Apache Airflow version

main (development)

### What happened

when I start airflow 2.4.0b1 with the `apache-airflow-providers-google==8.3.0`

the webserver log give : 

```log
[2022-09-08 14:39:53,158] {webserver_command.py:251} ERROR - [0 / 0] Some workers seem to have died and gunicorn did not restart them as expected
[2022-09-08 14:39:53,275] {providers_manager.py:228} WARNING - Exception when importing 'airflow.providers.google.common.hooks.base_google.GoogleBaseHook' from 'apache-airflow-providers-google' package
2022-09-08T14:39:53.276959961Z Traceback (most recent call last):
2022-09-08T14:39:53.276965441Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers_manager.py", line 260, in _sanity_check
2022-09-08T14:39:53.276969533Z     imported_class = import_string(class_name)
2022-09-08T14:39:53.276973476Z   File "/usr/local/lib/python3.8/site-packages/airflow/utils/module_loading.py", line 32, in import_string
2022-09-08T14:39:53.276977496Z     module = import_module(module_path)
2022-09-08T14:39:53.276981203Z   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
2022-09-08T14:39:53.276985012Z     return _bootstrap._gcd_import(name[level:], package, level)
2022-09-08T14:39:53.277005418Z   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2022-09-08T14:39:53.277011581Z   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2022-09-08T14:39:53.277016414Z   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2022-09-08T14:39:53.277020883Z   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2022-09-08T14:39:53.277025840Z   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2022-09-08T14:39:53.277029603Z   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2022-09-08T14:39:53.277032868Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/common/hooks/base_google.py", line 49, in <module>
2022-09-08T14:39:53.277036076Z     from airflow.providers.google.cloud.utils.credentials_provider import (
2022-09-08T14:39:53.277038762Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/cloud/utils/credentials_provider.py", line 36, in <module>
2022-09-08T14:39:53.277041651Z     from airflow.providers.google.cloud._internal_client.secret_manager_client import _SecretManagerClient
2022-09-08T14:39:53.277044383Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/cloud/_internal_client/secret_manager_client.py", line 26, in <module>
2022-09-08T14:39:53.277047248Z     from airflow.providers.google.common.consts import CLIENT_INFO
2022-09-08T14:39:53.277050101Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/common/consts.py", line 23, in <module>
2022-09-08T14:39:53.277052974Z     CLIENT_INFO = ClientInfo(client_library_version='airflow_v' + version.version)
2022-09-08T14:39:53.277055720Z AttributeError: 'str' object has no attribute 'version'
[2022-09-08 14:39:53,299] {providers_manager.py:228} WARNING - Exception when importing 'airflow.providers.google.cloud.hooks.cloud_sql.CloudSQLHook' from 'apache-airflow-providers-google' package
2022-09-08T14:39:53.300816697Z Traceback (most recent call last):
2022-09-08T14:39:53.300822358Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers_manager.py", line 260, in _sanity_check
2022-09-08T14:39:53.300827098Z     imported_class = import_string(class_name)
2022-09-08T14:39:53.300831757Z   File "/usr/local/lib/python3.8/site-packages/airflow/utils/module_loading.py", line 32, in import_string
2022-09-08T14:39:53.300836033Z     module = import_module(module_path)
2022-09-08T14:39:53.300840058Z   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
2022-09-08T14:39:53.300844580Z     return _bootstrap._gcd_import(name[level:], package, level)
2022-09-08T14:39:53.300862499Z   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2022-09-08T14:39:53.300867522Z   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2022-09-08T14:39:53.300871975Z   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2022-09-08T14:39:53.300876819Z   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2022-09-08T14:39:53.300880682Z   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2022-09-08T14:39:53.300885112Z   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2022-09-08T14:39:53.300889697Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/cloud/hooks/cloud_sql.py", line 51, in <module>
2022-09-08T14:39:53.300893842Z     from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
2022-09-08T14:39:53.300898141Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/common/hooks/base_google.py", line 49, in <module>
2022-09-08T14:39:53.300903254Z     from airflow.providers.google.cloud.utils.credentials_provider import (
2022-09-08T14:39:53.300906904Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/cloud/utils/credentials_provider.py", line 36, in <module>
2022-09-08T14:39:53.300911707Z     from airflow.providers.google.cloud._internal_client.secret_manager_client import _SecretManagerClient
2022-09-08T14:39:53.300916818Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/cloud/_internal_client/secret_manager_client.py", line 26, in <module>
2022-09-08T14:39:53.300920595Z     from airflow.providers.google.common.consts import CLIENT_INFO
2022-09-08T14:39:53.300926003Z   File "/usr/local/lib/python3.8/site-packages/airflow/providers/google/common/consts.py", line 23, in <module>
2022-09-08T14:39:53.300931078Z     CLIENT_INFO = ClientInfo(client_library_version='airflow_v' + version.version)
2022-09-08T14:39:53.300934596Z AttributeError: 'str' object has no attribute 'version'
....
```

### What you think should happen instead

_No response_

### How to reproduce

_No response_

### Operating System

ubuntu 22.04.1

### Versions of Apache Airflow Providers

_No response_

### Deployment

Other

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:
This is introduced by the lazy-loading PR (#24486). It loads `from airflow import version` incorrectly; that value should point to the `version` module, but instead the attribute is being loaded.

Resolving patch:
diff --git a/airflow/__init__.py b/airflow/__init__.py
--- a/airflow/__init__.py
+++ b/airflow/__init__.py
@@ -26,12 +26,13 @@
 isort:skip_file
 """
 
-
 # flake8: noqa: F401
 
+from __future__ import annotations
+
 import os
 import sys
-from typing import Callable, Optional
+from typing import Callable
 
 from airflow import settings
 
@@ -47,7 +48,7 @@
 if not os.environ.get("_AIRFLOW__AS_LIBRARY", None):
     settings.initialize()
 
-login: Optional[Callable] = None
+login: Callable | None = None
 
 PY36 = sys.version_info >= (3, 6)
 PY37 = sys.version_info >= (3, 7)
@@ -55,36 +56,31 @@
 PY39 = sys.version_info >= (3, 9)
 PY310 = sys.version_info >= (3, 10)
 
-# Things to lazy import in form 'name': 'path.to.module'
-__lazy_imports = {
-    'DAG': 'airflow.models.dag',
-    'Dataset': 'airflow.datasets',
-    'XComArg': 'airflow.models.xcom_arg',
-    'AirflowException': 'airflow.exceptions',
-    'version': 'airflow.version',
+# Things to lazy import in form {local_name: ('target_module', 'target_name')}
+__lazy_imports: dict[str, tuple[str, str]] = {
+    'DAG': ('.models.dag', 'DAG'),
+    'Dataset': ('.datasets', 'Dataset'),
+    'XComArg': ('.models.xcom_arg', 'XComArg'),
+    'AirflowException': ('.exceptions', 'AirflowException'),
+    'version': ('.version', ''),
+    '__version__': ('.version', 'version'),
 }
 
 
 def __getattr__(name: str):
     # PEP-562: Lazy loaded attributes on python modules
-    module_attr = name.rsplit('.', 1)[-1]
-    path: Optional[str]
-    if name == '__version__':
-        module_attr = 'version'
-        path = 'airflow.version'
-    else:
-        path = __lazy_imports.get(name)
-    if not path:
+    module_path, attr_name = __lazy_imports.get(name, ('', ''))
+    if not module_path:
         raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
 
-    import operator
+    import importlib
 
-    # Strip off the "airflow." prefix because of how `__import__` works (it always returns the top level
-    # module)
-    without_prefix = path.split('.', 1)[-1]
+    mod = importlib.import_module(module_path, __name__)
+    if attr_name:
+        val = getattr(mod, attr_name)
+    else:
+        val = mod
 
-    getter = operator.attrgetter(f'{without_prefix}.{module_attr}')
-    val = getter(__import__(path))
     # Store for next time
     globals()[name] = val
     return val


Test patch: