Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'pydantic_core._pydantic_core.Url' object has no attribute 'strip' #438

Open
ct2034 opened this issue Mar 25, 2024 · 4 comments

Comments

@ct2034
Copy link

ct2034 commented Mar 25, 2024

When I run the demo with
promnesia demo https://github.com/karlicoss/exobrain and then the browser extension tries to access /visits, I get:

  File "/home/user/.local/lib/python3.10/site-packages/promnesia/server.py", line 164, in search_common
    original_url = url and url.strip()
@ankostis
Copy link
Contributor

I'm getting the same, with fresh install. Any ideas why?

whacked added a commit to whacked/setup that referenced this issue Jun 19, 2024
karlicoss/promnesia#438

```
AttributeError: 'pydantic_core._pydantic_core.Url' object has no
attribute 'strip'
```

is thrown on every page access.

this is most likely caused by an API breakage between pydantic 1->2;
this commit tricks fastapi into thinking it uses the latest version
of pydantic in the nixpkgs (2.6.3 as of this commit) but pins it to
1.10.16
@whacked
Copy link

whacked commented Jun 19, 2024

I found this thread after encountering the same issue. This is most likely a result of some dependency tree update involving fastapi, under which it used to use pydantic 1.. but if you update everything to latest, you get 2... This is what I suspected after running pipdeptree, which shows that fastapi is responsible for pulling in pydantic. Fastapi says it's compatible with all pydantic versions 1+ though.

tl,dr: downgrade pydantic. I have tested it with 1.10.16 (the latest in the 1.. versions) and the error goes away.

FWIW, I run promnesia inside a nix shell; swapping out pydantic within fastapi took a bit of head bashing, so if it helps any other nix users, you can reference my expression here: https://github.com/whacked/setup/blob/f46e7c85bcc2548f2fed831b0f2a20cbb0c7ccc7/nix/pkgs/misc/promnesia/default.nix

If you don't use nix you can probably just run pip install pydantic==1.10.16 but don't quote me :-)

@whacked
Copy link

whacked commented Jun 19, 2024

also for reference, here's my current pipdeptree for my promnesia environment after fixing the error. It might not be minimal, but should be close.

beautifulsoup4==4.12.3                                     
└── soupsieve [required: >1.2, installed: 2.5]                                                          
chardet==5.2.0             
httptools==0.6.1           
logzero==1.7.0                                                                                          
lxml==5.1.0                                                
mistletoe==1.3.0 
pipdeptree==2.22.0
├── packaging [required: >=23.1, installed: 24.0]
└── pip [required: >=23.1.2, installed: 24.0]                                                           
poetry-core==1.9.0                                         
promnesia==1.2.20230515                                                                                 
├── appdirs [required: Any, installed: 1.4.4]                                                           
├── cachew [required: >=0.8.0, installed: 0.11.0]
│   ├── appdirs [required: Any, installed: 1.4.4]
│   └── SQLAlchemy [required: >=1.0, installed: 2.0.30]                                                 
│       ├── greenlet [required: !=0.4.17, installed: 3.0.3]                                          
│       └── typing_extensions [required: >=4.6.0, installed: 4.11.0]
├── fastapi [required: Any, installed: 0.110.2]     
│   ├── pydantic [required: >=1.7.4,<3.0.0,!=2.1.0,!=2.0.1,!=2.0.0,!=1.8.1,!=1.8, installed: 1.10.16]
│   │   └── typing_extensions [required: >=4.2.0, installed: 4.11.0]
│   ├── starlette [required: Any, installed: 0.37.2]                                                    
│   │   └── anyio [required: >=3.4.0,<5, installed: 4.3.0]                                              
│   │       ├── idna [required: >=2.8, installed: 3.7]
│   │       └── sniffio [required: >=1.1, installed: 1.3.1] 
│   └── typing_extensions [required: >=4.8.0, installed: 4.11.0]                                        
├── more-itertools [required: Any, installed: 10.2.0]                                                   
├── pytz [required: Any, installed: 2024.1]
├── SQLAlchemy [required: Any, installed: 2.0.30]                                                       
│   ├── greenlet [required: !=0.4.17, installed: 3.0.3]                                                 
│   └── typing_extensions [required: >=4.6.0, installed: 4.11.0]
├── tzlocal [required: Any, installed: 5.2]
├── urlextract [required: Any, installed: 1.9.0]
│   ├── filelock [required: Any, installed: 3.13.4]                                                     
│   ├── idna [required: Any, installed: 3.7]                                                            
│   ├── platformdirs [required: Any, installed: 4.2.0]                                                  
│   └── uritools [required: Any, installed: 4.0.2]                                                      
└── uvicorn [required: Any, installed: 0.29.0]                                                          
    ├── click [required: >=7.0, installed: 8.1.7]                                                       
    └── h11 [required: >=0.8, installed: 0.14.0]                                                        
python-dotenv==1.0.1                                                                                    
setuptools-scm==8.0.4
├── packaging [required: >=20, installed: 24.0]                                                         
├── setuptools [required: Any, installed: 69.5.1.post0]
└── typing_extensions [required: Any, installed: 4.11.0]                                                
six==1.16.0                                                                                             
uvloop==0.19.0                                             
watchfiles==0.21.0
└── anyio [required: >=3.0.0, installed: 4.3.0]
    ├── idna [required: >=2.8, installed: 3.7]
    └── sniffio [required: >=1.1, installed: 1.3.1]
websockets==12.0

@karlicoss
Copy link
Owner

Hey everyone, sorry not responded earlier!
That's surprising -- I think I saw this error and specifically fixed it, several months before the issue was reported!
de891a6

I never seen the error on CI since or anywhere else -- I also recently had a full reinstall from scratch on my PC, and promnesia is working.

Just for the reference, here are the relevant versions I have:

python: 3.12 (although all versions from 3.9 are tested on CI)
promnesia -- latest master
fastapi==0.115.0
pydantic==2.9.2
pydantic_core==2.23.4
uvicorn==0.30.6

I suspect this is some intermittent issue caused by weird fastapi/pydantic/uvicorn version mismatch -- if people could try again with latest versions (pip3 install -U ...), and take note of these versions before and after the upgrade this would be super helpful -- perhaps we could figure out the offending combination of versions and exclude it from promnesia setup file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants