question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested attribute acccess

See original GitHub issue

Brief summary of issue / Description of requested feature:

When using complex data types on object attrs, accessing nested keys/indexes would be awesome.

Steps to reproduce the issue / Reasons for adding feature:

  1. set here/test_list = ['this', 'that', 'the other']
  2. set here/test_list/0

Error output / Expected result of feature

Expected: Attribute Location Name/test_list/0 = this Actual: Attribute Location Name/test_list = ['This', 'that', 'the other'] Location Name has no attribute '0'.

Extra information, such as Evennia revision/repo/branch, operating system and ideas for how to solve / implement:

Looks like search_for_obj in evennia/commands/default/building.py would be the place to implement this chained attr lookup. Shouldn’t be too hard to implement, but would break folks expecting the multiple attr lookup, so it might need some new semantics/command.

I’m happy to attempt a PR if there is consensus on the interface.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
aarcrocommented, Sep 15, 2019

Perfect. Yes, would have to parse and sanitize ourself, not eval. We’d probably want to check for the exact name before attempting nested access, just in case there’s an existing attribute with [] in the name.

On Sun, Sep 15, 2019, 8:02 AM Griatch notifications@github.com wrote:

@aarcro https://github.com/aarcro This would make the set command a lot more powerful and would be a useful addition. I have some comments on the syntax though, should you feel like trying your hand at an implementation.

When coming to these kind of operations you are accessing Python structures stored in the Attribute. So I think it may be better and more intuitive to use Python syntax for it and implement this kind of operation just the way as you would expect in Python - that is, a syntax like

set here/test_list[0] = ‘foo’ set here/test_dict[‘bar’] = 32342 set here/test_dict_list[‘bar’][4] = ‘test’

One key thing to remember with any such implementation is that Python eval or exec must never be used to perform the operation - this would be a major security issue (making set possible to make work as the py command). Rather, the [ ] argument must be manually parsed and the content used to query the value in the Attribute, relaying proper, sanitized errors to the user.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/evennia/evennia/issues/1928?email_source=notifications&email_token=AACEJLNWKZBIBFY2MJ5IVH3QJYP6JA5CNFSM4IWY6DCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XPLGQ#issuecomment-531559834, or mute the thread https://github.com/notifications/unsubscribe-auth/AACEJLNXORYH2YBSAZHRFTTQJYP6JANCNFSM4IWY6DCA .

0reactions
aarcrocommented, Sep 22, 2019

The other option is to take insert/append out completely, but then you can only add to a list by copy/pasting the value and editing, the same as today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rails - How do you access nested params attribute?
and I want to access the user_id to change it. I tried params[:item][:user_items_attributes][0] and it doesn't work. I also tried params[:item][: ...
Read more >
Creating and using nested attributes - Algolia
Nested attributes are a way of applying sub-categories to your attributes. For instance, instead of having a single searchable attribute ...
Read more >
ActiveRecord::NestedAttributes::ClassMethods - Rails API
Active Record Nested Attributes Nested attributes allow you to save attributes on associated records through the parent.
Read more >
Attribute-Based Access control for nested attributes
Nested attributes are a form of hierarchy, but they are most useful for organization of attribute names. Examples: user.degree.university ...
Read more >
Java BeanUtils - Nested Property Access - Tutorialspoint
You can access the value of nested property of the bean by concatenating the property names of the access path by using "."...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found