Unable to __init__ component form

I am showing a form inside an alert window, I am using the suggested way:

c = frm_starpvda_read(starpvda=starpvda, session=self.cur_session['sessione'])
alert(content=c, large=True, buttons=[('OK',None)])

The form is set up to be used as a custom component and, in the “Custom Component Configuration” window, I specified the two parameters “starpvda” and “session”.

This piece of code worked like a charm up to now.
Now, apparently withou any reason, I have not changed neither the custom component definition nor the way I instantiate it, I get the error:

TypeError: init() takes atleast 3 arguments (2 given) at [frm_stagione_zoo, line 97](javascript:void(0))

How is that? The only way I can fix this apparently broken behaviour is to switch back to an earlier version of the application and restart… that’s frustrating!

Thanks

Just to confirm, is line 97 in frm_stagione_zoo that c = frm_starpvda_read(...) line you show above?

If so, please can you show the def __init__ line for frm_starpvda_read?

Hi David,
thanks for your quick reply.
Yes, line 97 in frm_stagione_zoo* is the

c = frm_starpvda_read(...)

line.


The ini for the form is the following:

class frm_starpvda_read(frm_starpvda_readTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    # Any code you write here will run when the form opens.
    # My cool code follows :)


And just to clarify better what I meant when I wrote:

The form is set up to be used as a custom component and, in the “Custom Component Configuration” window, I specified the two parameters “starpvda” and “session”.


Thanks for your help, really much appreciated.

BR!

Is this a simplified version of what you’ve done?

https://anvil.works/build#clone:7PFOSQIIHHOLKWKM=WBMMHHT5U4VU6B6NSEIN65S6

If it is, then I might need to see your project if that’s permissible, because that works for me.

If not, then I might have misunderstood.

Hi David

Is this a simplified version of what you’ve done?

Yes i think so.

If it is, then I might need to see your project if that’s permissible, because that works for me.

Absolutely permissible, I didn’t hope to have you have a look at my code.
You can clone the app with this link:

In order to reproduce the error, follow these steps:

1.Login

2.Click on the calendar link

3.Choose 28/06/2019

4.Get the error

Thanks and BR!
Great support!!

I’m sorry but I think this needs a greater mind than mine. I can’t call that form with any set of parameters that doesn’t give exactly the same error.

If you look at the stack trace in the error, the final line :

called from [rp_zoo_session_log, line 20]

there is a multi-parent reference - it’s possible the code is confused as to where it is, but that’s clutching at straws.

Why did it used to work? Well, I know Skulpt (the client side Python interpreter) has gone through some updates recently. It’s possible that a bug got introduced (or one your code inadvertently relied on got squashed).

Sorry I can’t be more help. You might need Anvil Central on this one.

If I have a flash of inspiration, I’ll post back.

David thanks for your help.
rp_zoo_session_log is the Repeating Panel corresponding to the line of the table where you clicked “28/06/2019”.
It is a Repeating Panel of frm_stagione_zoo.
Line 20 is ugly with those parent.parent.parent.... etc I agree completely but I didn’t find a different way to code it.
What I want to do there, is to call frm_stagione_zoo.btn_refresh_data_click(... which will refresh data and update the view, but I’m inside rp_zoo_session_log .
I’d love to learn a more elegant way to do that.

Why did it used to work? Well, I know Skulpt (the client side Python interpreter) has gone through some updates recently. It’s possible that a bug got introduced (or one your code inadvertently relied on got squashed).

I doubt it’s an update to Skulpt.
As I stated in my first post, in the original App’s version history I have a working version of the app with the same identical code.
The currently published App has the very same code and works.
If you think it can be useful, I can share that version too.
Then, while I am making improvements to other parts of the App, this part breaks.

BTW, what’s Anvil Central?

Thanks a lot David, BR

(I’m out of the office for a bit now, sorry. Anvil Central is my name for @meredydd, @daviesian, @shaun & @bridget, the core Anvil team)

The fact the method you’re using both worked and works in an isolated project implies heavily to me that something is causing confusion in that version of the app. I’m not quite sure how we go about debugging that. I think the main team might be better placed to either do that or point us in the right direction.

I cloned the app and played with it a little, and I can’t figure out what causes the problem.

I tried adding parameters to frm_starpvda_read.__init__(), but the error message doesn’t change, which makes me think that the import doesn’t import the form I modified, perhaps there is a problem with the import?

At this point I would clone the app with git (click on View history, then click on the Clone with Git button) and check the diff between the current version and the working version. If you are familiar with git this should be enough to put you on the right path. If you are not familiar with git… ask and we can help you.

Use PyCharm or Visual Studio Code as interfaces for git can be very helpful.

1 Like

My thoughts exactly (I did the same). Wonder if something has got corrupted somewhere.

+1 for that.

Hi Stefano
I’m new to git, I downloaded and installed it.
I generated my public key with the command ssh-keygen -t rsa
Then, in my ~/.ssh/id_rsa.pub file I copied the whole line beginning with ssh-rsa … and pasted it into this box:

After that I tried both git-bash and PyCharm (which I regularly use):
git-bash
Proxy set-up editing my .gitconfig file:

[http]
   proxy = https://<my username>:<my password>@proxy.corporate.com:port

Tried to clone issuing the git clone command suggested in the Anvil IDE box but I get:

Cloning into '<PRIVATE APP KEY>'...
ssh: connect to host anvil.works port 2222: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

PyCharm
Proxy set up in Preferences and successfully tested accessing www.google.com, so I guess that’s ok.

In the main PyCharm window:


Then

where I get this error.

What have I done wrong this time? :slight_smile:

Thanks and BR

Ok it must be the proxy.
Without proxy I have been able to clone the Git repository and now I can check version history with PyCharm.
Here’s the comparison between publshed (and working) verison and current (and not working) version:

What’s evident is that property “starpvda” has been changed from String to Object,
but still I can’t see any reason why init should give such error.

Should I check some other file?

Thanks again guys.

The only changes visible here are on the code that works on the logic. I think your problem is somewhere else.

Can you check the diff on all the other files?

Especially the yaml files?

You don’t have access to the yaml file from the web interface, and you shouldn’t modify them from git, otherwise you risk to brain damage the app. They describe what’s what and looking at them you can see what changed. Sometimes that’s enough for you to understand where to investigate.

Long time ago I had an app that once in a while would add spaces to the yaml file and stop loading on the IDE. I had to fix it by pulling with git, removing the spaces from the yaml files and pushing. It happened 3-4 times during a week, then never happened again. I guess the bug has been fixed.

I diffed the whole repo between published version and current version.
I can’t find anything relevant to my issue, but I’m no blackbelt with YAML definitions at all.
If you are still willing to help, this diff link will stay for 24 hours.
Diffy temporary link
I can upload the diff output too, but that’s more difficult to read imho.

Thanks and BR

The error is actually coming from cst_starpvda_print.__init__, not frm_starpvda_read.__init__.

cst_starpvda_print is a Custom Component with a property of type object, which must be set at runtime.

I’ve fixed the problem by instantiating a cst_starpvda_print in code:

from cst_starpvda_print import cst_starpvda_print

class frm_starpvda_read(frm_starpvda_readTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    self.cst_starpvda_print_1 = cst_starpvda_print(starpvda=self.starpvda, session=self.session)
    self.add_component(self.cst_starpvda_print_1)
    # ...

There was also a syntax error in the JavaScript in cst_starpvda_print:

        printWindow.document.write/'        <img src="');

(The / should be a ( )

The alert now comes up and the print button works.

Here’s a fixed version of the app.

https://anvil.works/build#clone:MAU6T2TDEID2NVY7=AEZPYLFR4UGJP26PEMICME67

@shaun - how did you find that? Would be great to know for future reference…

Wow that’s a valuable lesson to learn!
I just add, for the sake of completion for those who could find this post useful, that I had to remove cst_starpvda_print_1 from the form in design view.

Shaun, you’re my hero, really, how did you manage to find that?
What clues did you follow?

Thanks a lot guys for this great support!!

@david.wylie @aldo.ercolani

I elimnated as many hypotheses as possible:

  • I renamed the frm_starpvda_read Form to F, thinking there might be bug with snake case names
  • I rewrote the __init__ method from scratch to be sure it’s nothing about the logic in that method (and there’s no hidden unicode characters or anything)
  • I removed the additional arguments in __init__'s signature
  • I called F() from the first line of the startup Form (after self.init_components())

At that point, there was nothing left but the components on the page, so it must have been a problem with one of them.

4 Likes

Ah ok, so no magic debug that we don’t have access to then. Just good old fashioned working through it all.

1 Like

…and in a well-defined, helpful order.

There’s also a hint of science here: eliminate one variable at a time.