[Fixed] AttributeError in the designer

Hello community,
it’s been long since last time I asked for help, but today unfortunately I cannot avoid that.

I have a custom component with properties and events that has just stopped working and I am not able to debug properly because of this error in the IDE.

As you can see from this animated GIF:


- GIF - Imgur
when I click on the custom component in the design view, I get the error:

AttributeError: 'privacy_component' object has no attribute 'send_data_label'

The property send_data_label is indeed defined, and it looks correct to me:

This error prevents the properties section, on the right, to switch to the properties of the custom component, and I need that to work in order to check/modify settings for the event that the custom component raises:
image

I can’t figure out how to fix that by myself, it doesn’t look a code/settings issue, it looks to me a designer bug.

– EDIT –

Comparing the component configuration YAML between an app where it works, against this app I need to troubleshoot, it is evident that I didn’t specify an event handler in the latter:
working app

    - components:
      - event_bindings: {x_something_clicked: check_fields}
        layout_properties: {grid_position: 'MXGMTN,MSNKRC'}
        name: pc_privacy
        properties: {}

non working app

    - components:
      - layout_properties: {grid_position: 'RKJNPH,KWIZHN'}
        name: pc_privacy
        properties: {}

But I can’t fix that until the designer’s properties section shows up when I click on it.
Now I’ll try to modify the YAML by hand and import it back into a new app, and see what happens, however this is a only workaround.

– LAST EDIT –

The workaround above didn’t work.
However, I remembered I could set the event handler by code too, so this simple 1 liner did the job:

    # set the event handler for the privacy component
    self.pc_privacy.add_event_handler('x_something_clicked', self.check_fields)

→ However, this’s still a workaround, the IDE should work properly with that custom component.

1 Like

Hard to know exactly what you have going on but I can share how I’ve been doing custom component properties that may help. In this case here I’ve setup a component propery called my_attr.

class CustomComponent(CustomComponentTemplate):
    def __init__(self, **properties):
        self._my_attr = None

        self.init_components(**properties)        

    @property
    def my_attr(self) -> int:
        return self._my_attr

    @my_attr.setter
    def my_attr(self, new_value: int):
        self._my_attr = new_value
        # Do any updates required, this keeps the editor dynamic

I create a private version of all my attributes before the init_components() so I don’t get any “not defined” type errors.

I then create a getter and setter for each attribute. The setter allows the designer to respond to component property changes.

We had a look at this one over messages

The issue was that the @my_atter.setter was a dummy placeholder function
e.g.

    @property
    def my_attr(self) -> int:
        return self._my_attr

    @my_attr.setter
    def my_attr(self, new_value: int):
        # placeholder
        pass 

Which the designer didn’t like since asking for the my_attr was resulting in the AttributeError

We’ve implemented (but not yet deployed) a fix so that you’ll still see the error in the Designer Output, but you will also be able to still interact with the component

1 Like

That’s true and that is because they were meant to be readonly properties, read from the configuration and not meant to be set.
So the setter did nothing while in the initialisation code I had:
self._my_attr = self._config_data['my_attr'] if 'my_attr' in self._config_data else ''
In this case, what should’ve been the most correct approach?
Thanks

Just delete the setter altogether may be better. for python you definitely don’t need a setter for a read only prop.

1 Like

Yes, and also, if you don’t intend for them to be set in the designer properties panel
then you should remove them from the list of properties in the custom component dialog.

Just having the property getters as @duncan_richards12 will be enough for them to be autocompleted in code

2 Likes

Thank you guys, I’m going to fix the code the way you say.
Anvil always the best team and community.
:muscle:
BR