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

Fix access to catalog dict #9

Closed

Conversation

lpillmann
Copy link

@lpillmann lpillmann commented Jan 15, 2020

Description of change

This PR fixes the dict access bug cited in the issue #6. Previously, the code broke when running in sync mode

python \{\{cookiecutter.package_name\}\}/__init__.py -c sample_config.json --properties catalog.json

with this error:

CRITICAL 'dict' object has no attribute 'streams'
Traceback (most recent call last):
  File "{{cookiecutter.package_name}}/__init__.py", line 95, in <module>
    main()
  File "/Users/luipillmann/opt/anaconda3/envs/singer-template/lib/python3.7/site-packages/singer/utils.py", line 229, in wrapped
    return fnc(*args, **kwargs)
  File "{{cookiecutter.package_name}}/__init__.py", line 92, in main
    sync(args.config, args.state, catalog)
  File "{{cookiecutter.package_name}}/__init__.py", line 64, in sync
    selected_stream_ids = get_selected_streams(catalog)
  File "{{cookiecutter.package_name}}/__init__.py", line 54, in get_selected_streams
    for stream in catalog.streams:
AttributeError: 'dict' object has no attribute 'streams'

The error was caused by wrong syntax to access dict values in Python. The code used dot notation (my_dict.key), whilst the right syntax is either with brackets (my_dict["key"]) or using the get method (my_dict.get("key"). I chose the former option, since I consider it more readable.

Manual QA steps

Add a file catalog.json in singer-tap-template/{{cookiecutter.project_name}} with the contents provided when running python \{\{cookiecutter.package_name\}\}/__init__.py -c sample_config.json --discover.

Then, run

python \{\{cookiecutter.package_name\}\}/__init__.py -c sample_config.json --properties catalog.json

from singer-tap-template/{{cookiecutter.project_name}} folder. The expected behavior is no return with no errors.

Risks

No risks since this addresses only a few lines of code with very limited scope.

Rollback steps

  • revert this branch

@aaronsteers
Copy link
Contributor

aaronsteers commented Feb 7, 2020

replaced by #11

@lpillmann lpillmann closed this Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants