garth icon indicating copy to clipboard operation
garth copied to clipboard

garth.UserProfile.get() and garthUserSettings.get() throw an error

Open AndreaMariani-AM opened this issue 1 year ago • 1 comments

Hi,

Thanks for the package, really useful. I've noticed that when running garth.UserProfile.get() and garth.UserSettings.get() both throw an error during validation with pydantic.

Here's the error for UserProfile. The same happens for UserSettings but with 8 validation errors.

"---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[115], line 1
----> 1 garth.UserProfile.get()
      2 #garth.connectapi(\"/userprofile-service/socialProfile\")
      3 camel_to_snake_dict(garth.connectapi(\"/userprofile-service/userprofile/user-settings\"))

File /hpcnfs/scratch/DP/amariani/Amariani/Polycomb_regulation/code/puffin/puffin_env/lib/python3.8/site-packages/garth/users/profile.py:80, in UserProfile.get(cls, client)
     78 profile = client.connectapi(\"/userprofile-service/socialProfile\")
     79 assert isinstance(profile, dict)
---> 80 return cls(**camel_to_snake_dict(profile))

File /hpcnfs/scratch/DP/amariani/Amariani/Polycomb_regulation/code/puffin/puffin_env/lib/python3.8/site-packages/pydantic/_internal/_dataclasses.py:141, in complete_dataclass.<locals>.__init__(__dataclass_self__, *args, **kwargs)
    139 __tracebackhide__ = True
    140 s = __dataclass_self__
--> 141 s.__pydantic_validator__.validate_python(ArgsKwargs(args, kwargs), self_instance=s)

ValidationError: 1 validation error for UserProfile
profile_image_uuid
  Field required [type=missing, input_value=ArgsKwargs((), {'id': 349...: 0, 'user_pro': False}), input_type=ArgsKwargs]
    For further information visit https://errors.pydantic.dev/2.8/v/missing"

What works

running directly

garth.connectapi("/userprofile-service/socialProfile")
garth.connectapi("/userprofile-service/userprofile/user-settings")

works. Also, the function camel_to_snake_dict works as intended.

Let me know if you need more info. Thanks again.

Cheers, Andrea

AndreaMariani-AM avatar Jul 31 '24 10:07 AndreaMariani-AM

Hi @AndreaMariani-AM - happy to hear you're enjoying using Garth!

It should be a straightforward fix.

Could you create a fork with a branch that has the failing test?

Here's what you have to do:

  1. Login and save your tokens to the default path
  2. Run the tests with make test to make sure they all run
  3. Add a test that fails for your case. This'll record the request and response
  4. Push the failing test and VCR cassette to your branch

I can then use that to reproduce the issue. Once I can reproduce it with your VCR cassette, the fix should be simple.

Let me know if you need help with the steps above.

matin avatar Jul 31 '24 16:07 matin

What was the resolution?

matin avatar Aug 29 '24 19:08 matin

Hey, sorry i thought i'd posted it.

I still have to figure out exactly what the problem was, but it's definitely on my end. I was running in on a shared server before but locally works just fine. If i'll find more info i'll let you know.

Thanks again, Andrea

AndreaMariani-AM avatar Aug 30 '24 09:08 AndreaMariani-AM