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

Custom Request does not support lists #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rmporsch
Copy link

@rmporsch rmporsch commented Jun 22, 2021

Given we have the following request body:

{
  "instances": [
    {
      "text": "{{ text }}"
    }
    ]
}

The following method is unable to replace "{{ text }}" with the appropriate text.

def find_and_replace_value(obj, value, target='{{ text }}'):
    for k, v in obj.items():
        if v == target:
            obj[k] = value
            return
        if isinstance(v, dict):
            find_and_replace_value(v, value, target)

The proposed changes would address this issue.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

My test cases

Test A:

test_a = {
    "instances": [
        {
            "text": "{{ text }}"
        }
    ]
}

Test B

test_a = {
    "instances": [[
        {
            "text": "{{ text }}"
        }
    ]]
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Given we have the following request body:
```json
{
  "instances": [
    {
      text: "{{ text }}"
    }
    ]
}
```
The following method is unable to replace "{{ text }}" with the appropriate text.

```python
def find_and_replace_value(obj, value, target='{{ text }}'):
    for k, v in obj.items():
        if v == target:
            obj[k] = value
            return
        if isinstance(v, dict):
            find_and_replace_value(v, value, target)
```

The proposed changes would address this issue.
@rmporsch rmporsch changed the title Custom Reset Request does not support lists in Custom Request does not support lists in Jun 22, 2021
@rmporsch rmporsch changed the title Custom Request does not support lists in Custom Request does not support lists Jun 22, 2021
@rmporsch
Copy link
Author

As a side question to this PR:
image
This seems not to be the correct way to do it. Since the value seems to be passed as string if I am not wrong.
So how would I pass a nested dict in the body? Is the value ever serialized?

@rmporsch
Copy link
Author

@Hironsan not sure who the right person for this is but would love to get this merged.

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.

1 participant