Skip to content
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

[Mongodb Connection] AttributeError: 'bool' object has no attribute 'lower' #42930

Closed
1 of 2 tasks
FarouziAbir opened this issue Oct 11, 2024 · 5 comments · Fixed by #43024
Closed
1 of 2 tasks

[Mongodb Connection] AttributeError: 'bool' object has no attribute 'lower' #42930

FarouziAbir opened this issue Oct 11, 2024 · 5 comments · Fixed by #43024
Assignees
Labels
area:providers good first issue kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet provider:mongo

Comments

@FarouziAbir
Copy link

Apache Airflow Provider(s)

mongo

Versions of Apache Airflow Providers

No response

Apache Airflow version

2.10.2

Operating System

Redhat 9

Deployment

Virtualenv installation

Deployment details

No response

What happened

I create a new mongo connection on Airflow with the following input:
image

When I try to call the connection on my task on Airflow:

from airflow.providers.mongo.hooks.mongo import MongoHook
@task
def drop_table_from_mongo():
    mongo_conn = MongoHook(conn_id='QDATALAKE')
    #My code ...
    cnxn.close()

I have this error:
[2024-10-11, 08:44:07 UTC] {base.py:84} INFO - Retrieving connection 'QDATALAKE'
[2024-10-11, 08:44:07 UTC] {taskinstance.py:3310} ERROR - Task failed with exception
Traceback (most recent call last):
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 767, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 733, in _execute_callable
return ExecutionCallableRunner(
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 406, in wrapper
return func(self, *args, **kwargs)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/decorators/base.py", line 266, in execute
return_value = super().execute(context)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 406, in wrapper
return func(self, *args, **kwargs)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/operators/python.py", line 238, in execute
return_value = self.execute_callable()
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/operators/python.py", line 256, in execute_callable
return runner.run(*self.op_args, **self.op_kwargs)
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
File "/opt/airflow/dags/Erebia_Datalake_Source_Manuel.py", line 42, in drop_table_from_mongo
mongo_conn = MongoHook(conn_id='QDATALAKE')
File "/opt/airflow/venv/lib/python3.9/site-packages/airflow/providers/mongo/hooks/mongo.py", line 139, in init
self.allow_insecure = self.extras.pop("allow_insecure", "false").lower() == "true"
AttributeError: 'bool' object has no attribute 'lower'

What you think should happen instead

No response

How to reproduce

  1. Create a new connection
  2. Choose Mongo as type of connection
  3. Add Connection name, host, username, passeword and port
  4. Do not put anything in extra and do not check any option after extra
  5. Save the connection
  6. n a new Dag, import MongoHook
  7. Create a @task and call the mongo connection (like in the example below)
  8. When the Dag is exacuted, the exception is raised as in the logs below.

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@FarouziAbir FarouziAbir added area:providers kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Oct 11, 2024
Copy link

boring-cyborg bot commented Oct 11, 2024

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

@build3r
Copy link

build3r commented Oct 11, 2024

Looks like the issue might be because of the newly introduced ssl check boxes for mongo connection.
Minimal way to reproduce:

  1. Setup mongo connection in Airflow UI
  2. Open Python CLI on airflow server
  3. Import mongo hook from airflow.providers.mongo.hooks.mongo import MongoHook
  4. Try to connect mongo_hook = MongoHook(mongo_conn_id='mongo_default')
    Connection fails with
    AttributeError: 'bool' object has no attribute 'lower'

Removing the .lower from package works

@AkhilVinayakp
Copy link

Try adding the connection via cli.

airflow connections add '<connection_id_name>' \
    --conn-type 'mongo' \
    --conn-host '<host-ip>' \
    --conn-port '27017' \
    --conn-login '<your-username>' \
    --conn-password '<your-password>' 

@josix
Copy link
Contributor

josix commented Oct 14, 2024

It's probably caused from an inconsistent validation between get_extra_dejson and MongoHook initialization when building the connection, I could help revamp the validation logics here, feel free to assign it to me, thanks.

My previous workaround is adding quotes to the ssl field to make it as string.

@potiuk
Copy link
Member

potiuk commented Oct 14, 2024

Assigned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers good first issue kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet provider:mongo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants