jedcunningham commented on a change in pull request #17423:
URL: https://github.com/apache/airflow/pull/17423#discussion_r682957637



##########
File path: airflow/providers/postgres/hooks/postgres.py
##########
@@ -70,6 +70,7 @@ def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
         self.connection: Optional[Connection] = kwargs.pop("connection", None)
         self.conn: connection = None
+        self.schema: Optional[str] = kwargs.pop("schema", None)

Review comment:
       Instead, maybe this:
   ```suggestion
           if not hasattr(self, "schema"):
               self.schema: Optional[str] = kwargs.pop("schema", None)
   ```
   
   That should work for core both pre and post 2.2.0 and wouldn't break 
behavior of `get_uri` either like doing `__schema` does.

##########
File path: airflow/providers/postgres/hooks/postgres.py
##########
@@ -70,6 +70,7 @@ def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
         self.connection: Optional[Connection] = kwargs.pop("connection", None)
         self.conn: connection = None
+        self.schema: Optional[str] = kwargs.pop("schema", None)

Review comment:
       Good catch. One thing I don't love is now we possibly have both 
`__schema` and `schema` being used. It's particularly ugly if one wanted to 
change the schema after init. What if we just let the hooks also set `schema`?

##########
File path: airflow/providers/postgres/hooks/postgres.py
##########
@@ -70,6 +70,7 @@ def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
         self.connection: Optional[Connection] = kwargs.pop("connection", None)
         self.conn: connection = None
+        self.schema: Optional[str] = kwargs.pop("schema", None)

Review comment:
       Sorry, I should have included an example. This is what I meant:
   
   ```
   h = SomeHook(schema="foo")
   h.get_uri() # uses foo
   h.schema = "bar"
   h.get_uri() # still uses foo because of __schema
   ```
   
   That's why I'm thinking letting both `DbApiHook` and any derived hooks both 
set `schema` might be the best of both worlds here? Then the derived hooks 
could stop setting `schema` in Airflow 3 (or the next time they get a min core 
version bump really).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to