natanweinberger opened a new pull request #15425:
URL: https://github.com/apache/airflow/pull/15425


   This is a bug fix for the CLI command `connections_import`. I originally 
added this CLI functionality in #15177. The bug was reported by @mudravrik 
[here](https://github.com/apache/airflow/pull/15177#issuecomment-822056108).
   
   ## Root cause
   I called `load_connections_dict` with the connections filepath and thought 
it returned a list of dictionaries. During the loop in which I added and 
committed the connections to the DB, I called the dictionary method `.items()` 
on each connection. However, each connection was actually stored into a 
`Connection` model instance rather than a dictionary, so the call I made to 
`.items()` resulted in an AttributeError.
   
   ## Solution
   In taking a closer look at this issue, I realized the code block that 
contained the bug can be removed altogether. Having a list of `Connection` 
models (rather than dictionaries) eliminated the need to even examine the keys 
and values of the dictionaries, I had only done that to safely load the data 
into `Connection` models in the first place.
   
   To avoid future issues, I also changed how the tests work for providing 
sample data. Before, a dictionary of sample data was set as the return value of 
`load_connections_dict`, which I didn't notice returned a list of 
`Connections`. Now, that dictionary is set of the return value of a lower level 
function, `_parse_secrets_file`, which does no heavy lifting outside of parsing 
a JSON, YAML or env file.
   
   Bug originally introduced in #15177, which closed #9855.


-- 
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.

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


Reply via email to