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

Duplicate records when using state due to wrong where clause in query #49

Open
ednarb29 opened this issue Jan 27, 2022 · 0 comments
Open

Comments

@ednarb29
Copy link

I've installed the tap into a new virtual environment, obtained the required credentials from QBO, executed the tap in discovery mode to get the catalog, and then as described in the readme.

$ tap-quickbooks --config tap_config.json --catalog catalog.json >> state.json
$ tail -1 state.json > state.json.tmp && mv state.json.tmp state.json

After I manually modified the state.json from

{"type": "STATE", "value": {"bookmarks": {"accounts": {"LastUpdatedTime": "2022-01-26T14:17:18-08:00"}}}}

to

{"bookmarks": {"accounts": {"LastUpdatedTime": "2022-01-26T14:17:18-08:00"}}}

to make it work with the tap, I got a single duplicate entry.

I identified the reason for the tap's behavior in the file tap_quickbooks/query_builder.py. In my opinion, the where_baseis wrong:

def build_query(table_name, bookmark, start_position, max_results, additional_where=None):
    query_base = "SELECT * FROM {}".format(table_name)
    where_base = " WHERE Metadata.LastUpdatedTime >= '{}'".format(bookmark)

    where_clause = where_base
    if additional_where:
        where_clause = where_clause + " AND {}".format(additional_where)

    order_clause = " ORDER BY Metadata.LastUpdatedTime ASC STARTPOSITION {} MAXRESULTS {}".format(start_position, max_results)

    return query_base + where_clause + order_clause

It should be corrected from

where_base = " WHERE Metadata.LastUpdatedTime >= '{}'".format(bookmark)

to

where_base = " WHERE Metadata.LastUpdatedTime > '{}'".format(bookmark)

without the = operator.

After removing it, the duplicate entry disappeared.

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

No branches or pull requests

1 participant