Dependency was busting my code

Hi All,

It took me ages to find this out, so I’m hoping I can save you some time.
My app has some fairly simple methods which are called at load time in a Global module.

I started getting some very odd behaviour from my code, where the Exception messages would be something like :
function takes 1 positional argument, 2 were received…yet my function looked like this

def get_stuff(arg1, arg2):
do stuff
call other functions
return stuff

It was working fine a few days ago, then when I return to my code it has gone awry.
I went round the houses for ages on this, checking all the sub-function calls, restructuring my code etc etc.

It turned out that it had nothing to do with the functions, but that I had added a dependency to my python3 environment which was running in python2. If I removed the dependency then everything worked again. I don’t know precisely what it was that was causing the issue just that it was a dependency thing…I’m not that good at coding.

Anyway, I actually needed the code from that dependency, so I created a local module, and cut&pasted the code from the dependency into my app, used the same name for the module in my app as was in the dependency and all is now good.

So, if you’re struggling to find why your code has start behaving strangely, consider checking the dependencies. Even if the two things seem completely unrelated.

Hope this helps.
Boz

Could you share a little more?
If nothing changed in your apps and you started getting errors it’s something we would consider a possible bug.

Some clone links, code snippets and error output would be useful to get a sense of what was going on.

Hi Stu,

I’ve moved on with my code quite significantly, but I’ve tried to replicate the error by importing the dependency again.

Code in Global looks like this
try:

  myuuid,myuuid_row=anvil.server.call('get_uuid')
except Exception as E:
  print(f'in Global, cannot get myuuid or myuuid_row.  Error message is: {E}')

in ServerModule, the get_uuid function is defined as this:

# get uuids
@anvil.server.callable
def get_uuid():
  me=check_user()
  #uuid in user table is actually a link to another table
  uuid_string=me['uuid']['actual_id']
  uuid_row=me['uuid']
  print(f" in get_uuid my uuid is {uuid_string}")
  print(f" in get_uuid my uuid_row is {uuid_row}")
  return uuid_string, uuid_row

Error message is:
in Global, cannot get myuuid or myuuid_row. Error message is: not enough values to unpack (expected at least 2, got 1)

This is slightly different to the error message I got before.
If I remove the dependency (Clone of Form Validation), then it all works.

Apologies if I gave the impression that nothing changed in my apps, it had. I had imported this dependency. I had used that dependency successfully in a Proof of Concept app, so didn’t think that it might be the problem.
I don’t think it is a bug in anvil, I think it is me being silly and not thinking about the latest changes I had made to my environment/code.
Thanks for your help

1 Like

thanks for the update.

formatting code:
When pasting code it’s useful to format the code with back ticks ```

```python
# code goes here

```

Is it possible that the dependency you’re using also has a server function named get_uuid?

Try changing the name of your own function and see what happens, perhaps.

1 Like

Hi Owen,
Thanks for the idea. I did look into that at the time.
I wondered if I had declared get_uuid twice, or indeed if it was in the imported dependency, but I couldn’t find it. So I discounted that line of investigation. It still might be that, that is indeed the problem.

@stucork duly noted about the back ticks.

Cheers
Boz

1 Like