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

Bag: Improve access #1602

Merged
merged 2 commits into from
Apr 11, 2023
Merged

Conversation

patrickelectric
Copy link
Member

No description provided.

@joaoantoniocardoso
Copy link
Collaborator

I'm a bit lost here. What/how is the payload?

@patrickelectric
Copy link
Member Author

I'm a bit lost here. What/how is the payload?

payload is a json

if path == 'root':
current_data = payload
else:
dpath.new(current_data, path, payload, separator=".")
write_db(current_data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So.. Here we are replacing the entire db without checking if its structure is correct. I can't evaluate the implications because I'm not aware of the rest of the code, I believe in your judgment

Copy link
Collaborator

Choose a reason for hiding this comment

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

like.. a write_data("/root", {}) call would erase the db

Copy link
Member Author

Choose a reason for hiding this comment

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

like.. a write_data("/root", {}) call would erase the db

That's the point

Copy link
Member Author

Choose a reason for hiding this comment

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

I have created an endpoint to only do that, making it more explicit

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric patrickelectric changed the title Bag: add root key Bag: Improve access Apr 10, 2023
current_data = read_db()
try:
result = dpath.get(current_data, path, separator=".")
result = dpath.util.search(current_data, path)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I like this, what is the purpose of using search? I think if we have something like

{
  "potato: {
    "a": 1,
    "b": 2
    }
}

and we ask for "potato/a" we should just get 1, instead I'm getting:

{
  "potato: {
    "a": 1
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Check now

image

- Use '/' as separator
- Allow usage of wildcard * to get everything
- Create an endpoint to allow overwriting db

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Copy link
Collaborator

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

If write_data() is supposed to overwrite when the path already exists, this PR seems fine.

@patrickelectric patrickelectric merged commit 0186964 into bluerobotics:master Apr 11, 2023
5 checks passed
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.

None yet

3 participants