Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions airflow/providers/mongo/hooks/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class MongoHook(BaseHook):
when connecting to MongoDB.
"""

conn_name_attr = "conn_id"
conn_name_attr = "mongo_conn_id"
default_conn_name = "mongo_default"
conn_type = "mongo"
hook_name = "MongoDB"

def __init__(self, conn_id: str = default_conn_name, *args, **kwargs) -> None:
def __init__(self, mongo_conn_id: str = default_conn_name, *args, **kwargs) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This add breaking changes in case if user provide arguments as keyword:

MongoHook(conn_id="awesome-conn-id")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wesseldr Thanks for the contribution and your first PR! Definitely the docstring for the hook doesn't match what's actually required for use.

+1 on what @Taragolis mentioned.

We try to be very cognizant when thinking about backwards compat for users and try not to introduce breaking changes if avoidable. We really don't want users to upgrade a provider version and suddenly DAGs begin to break. In this situation, if the parameter name is changing, a DeprecationWarning should be raised that conn_id is deprecated and mongo_conn_id should be used. You can find a number of examples in other providers' hooks where a parameter is deprecated for reference on how to do this.

For the deprecation period, the hook should accept both conn_id and mongo_conn_id to maintain backwards compat and ultimately resolve to the self.mongo_conn_id value. Also the MongoSensor should ideally be updated to call this hook with keyword args.

The unit tests for the provider need to be updated accordingly too.

We're more than happy to help out if you are stuck. You can find us on Airflow Slack or we can communicate in this PR directly too.

super().__init__()
self.mongo_conn_id = conn_id
self.connection = self.get_connection(conn_id)
self.mongo_conn_id = mongo_conn_id
self.connection = self.get_connection(mongo_conn_id)
self.extras = self.connection.extra_dejson.copy()
self.client = None
self.uri = self._create_uri()
Expand Down