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

[AIRFLOW-3049] Add extra operations for Mongo hook #3890

Merged
merged 2 commits into from
Oct 29, 2018
Merged

[AIRFLOW-3049] Add extra operations for Mongo hook #3890

merged 2 commits into from
Oct 29, 2018

Conversation

dlebech
Copy link
Contributor

@dlebech dlebech commented Sep 12, 2018

Make sure you have checked all steps below.

Jira

Description

  • Here are some details about my PR, including screenshots of any UI changes:

This PR adds six extra operations to the Mongo hook: update, replace and delete as well as a *_many version for each of those.

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:
  • test_update_one
  • test_update_one_with_upsert
  • test_update_many
  • test_update_many_with_upsert
  • test_replace_one
  • test_replace_one_with_filter
  • test_replace_one_with_upsert
  • test_replace_many
  • test_replace_many_with_upsert
  • test_delete_one
  • test_delete_many

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added.

Code Quality

  • Passes git diff upstream/master -u -- "*.py" | flake8 --diff

This commit adds update, replace and delete operations for the Mongo
hook.
@dlebech
Copy link
Contributor Author

dlebech commented Sep 13, 2018

The Travis build seems to have failed for one of the environments. It runs on my own branch though: https://travis-ci.org/dlebech/incubator-airflow/builds/427786725


def replace_many(self, mongo_collection, docs,
filter_docs=None, mongo_db=None, upsert=False, collation=None,
**bulk_kwargs):
Copy link
Contributor

@Fokko Fokko Sep 15, 2018

Choose a reason for hiding this comment

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

Maybe call this one just kwargs as well, to make it congruent with the other calls.

:type filter_docs: list(dict)
:param mongo_db: The name of the database to use.
Can be omitted; then the database from the connection string is used.
:type mongo_db: str
Copy link
Contributor

Choose a reason for hiding this comment

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

The upsert and collation are missing from the docstring.

@dlebech
Copy link
Contributor Author

dlebech commented Sep 16, 2018

@Fokko thanks for the feedback. I've updated the parameter name and added tweaks to the documentation.

@Fokko
Copy link
Contributor

Fokko commented Sep 17, 2018

LGTM, one minor think. Recently we've moved to a Docker-compose based CI pipeline. Instead of mocking the requests, there is also a real mongo instance running. What are your opinions on mocking, or talking to a real mongo instance?

@dlebech
Copy link
Contributor Author

dlebech commented Sep 17, 2018

@Fokko Thanks!

Regarding mocking vs real instance, I'm not sure I'm in the best position to answer that since I basically just built this PR upon the pre-existing setup, so I cannot say why mongomock was originally chosen.

But it looks like a pretty good library for this kind of thing, and since Travis is already taking a very long time to run, I assume mocking speeds thing up a bit in this case. I don't know how much that matters, but at least from my perspective, it feels like mocking is an ok thing to do 🙂

Perhaps the original author @andscoop has a better opinion than mine?

@andscoop
Copy link
Contributor

@dlebech @Fokko When I was originally writing unit tests, I don't believe that we were using docker-compose, or if we were I was not aware of it. I'm not familiar with all the reasons for moving to docker-compose, but idk if I see a compelling reason to move away from mocking the responses in the hook as all responses are known before hand.

@ron819
Copy link
Contributor

ron819 commented Oct 29, 2018

@Fokko is this ready to merge?

@Fokko
Copy link
Contributor

Fokko commented Oct 29, 2018

Thanks, @dlebech. Merging to master!

@Fokko Fokko merged commit a314e8f into apache:master Oct 29, 2018
@dlebech dlebech deleted the more-mongo-hook-operations branch November 5, 2018 12:33
wyndhblb pushed a commit to asappinc/incubator-airflow that referenced this pull request Nov 9, 2018
This commit adds update, replace and delete operations for the Mongo
hook.
aliceabe pushed a commit to aliceabe/incubator-airflow that referenced this pull request Jan 3, 2019
This commit adds update, replace and delete operations for the Mongo
hook.
ashb pushed a commit that referenced this pull request Mar 26, 2019
This commit adds update, replace and delete operations for the Mongo
hook.
wmorris75 pushed a commit to modmed/incubator-airflow that referenced this pull request Jul 29, 2019
This commit adds update, replace and delete operations for the Mongo
hook.
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.

4 participants