Fix fastapi root path o2m m2m search#962
Conversation
sqladmin/application.py
Outdated
| self.favicon_url = favicon_url | ||
|
|
||
| if hasattr(self.app, "root_path"): | ||
| self.base_url = self.app.root_path + base_url |
There was a problem hiding this comment.
Should we do urljoin to make sure starting/ending slashes or joined properly?
There was a problem hiding this comment.
maybe
if hasattr(self.app, "root_path"):
parts = [p.strip("/") for p in [self.app.root_path, base_url] if p.strip("/")]
self.base_url = "/" + "/".join(parts)
There was a problem hiding this comment.
or better
self.base_url=urljoin(app.root_path+"/", base_url.lstrip("/"))
There was a problem hiding this comment.
I think urljoin will do that so:
self.base_url=urljoin(app.root_path, base_url)
There was a problem hiding this comment.
i've tried different paths, the only working way is to do
self.base_url=urljoin(app.root_path+"/", base_url.lstrip("/"))
There was a problem hiding this comment.
I think you are right, probably it should be changed to this:
self.base_url=os.path.join(app.root_path, base_url)Also a few other points:
- tests should be added
- there's an existing code using urljoin which I think should be changed to os.path.join
|
@mmzeynalli I was waiting for this comment to be resolved. I think it's a small change but we should also add tests for it |
|
@JartanFTW your PR #996 addresses this, right? |
From my understanding, yes. |
fix the search in one-to-many or many-to-many field if fastapi root_path is set
app = FastAPI(
root_path="/api",
)