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

Can't use create_merge_query endpoint, I get the following error "Object of type MergeQuerySourceQuery is not JSON serializable" #1536

Open
felschoen opened this issue Nov 7, 2024 · 2 comments · May be fixed by #1538
Labels
p3 Priority 3 python Python SDK issues

Comments

@felschoen
Copy link

Hello - we want to update some merged results on our instance using Looker SDK and Python. At the moment we are stuck to create a new merged_result_id which we need to update dashboards.

Everything works fine when I use Looker API Explorer in Looker, but when I then run the code (provided by the Looker API Explorer), I get the following Error: TypeError: Object of type MergeQuerySourceQuery is not JSON serializable. Looker SDK version is 24.18.1, so the latest.

I was also already in contact with Looker Support, but they could not help me.

Here is the code I am trying to run:

from looker_sdk.sdk.api40 import models as mdls

response = sdk.create_merge_query(
    body=mdls.WriteMergeQuery(
        dynamic_fields="[]",
        source_queries=[
            mdls.MergeQuerySourceQuery(
                name="Order Items",
                query_id="1234",
                query_slug="ahbgoiugbEAF1234"
            ),
            mdls.MergeQuerySourceQuery(
                merge_fields=[
                    mdls.MergeFields(
                        field_name="orders.paid_week",
                        source_field_name="orders.paid_week"
                    )
                ],
                name="Order Items 2",
                query_id="5678",
                query_slug="ah2b123123goiugbEAF1234"
            )
        ],
        total=False,
        vis_config={}
    ))
    
@github-actions github-actions bot added need triage p3 Priority 3 labels Nov 7, 2024
@drstrangelooker drstrangelooker added python Python SDK issues and removed need triage labels Nov 7, 2024
@felschoen
Copy link
Author

I found what needs to be changed:

In looker_sdk/rtl/serialize.py in the function called serialize, I changed the return from
json.dumps(data.encode("utf-8") to
json.dumps(data,default=lambda o: o.__dict__).encode("utf-8").

I did not test it if it breaks other stuff, but at least everything works for me now :)

@drstrangelooker
Copy link
Collaborator

Thanks for the solution. We will do some testing with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Priority 3 python Python SDK issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants