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

Multiple Admin Instances result in wrong URL's to the views #738

Open
2 tasks done
hochstibe opened this issue Apr 3, 2024 · 2 comments
Open
2 tasks done

Multiple Admin Instances result in wrong URL's to the views #738

hochstibe opened this issue Apr 3, 2024 · 2 comments

Comments

@hochstibe
Copy link

hochstibe commented Apr 3, 2024

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

I have an application with the option of extensions. My idea was to have an admin page for the main application and separate admin pages for the extensions.

You can have multiple instances of Admin running, but the links to the Views on the left point to wrong URL's.

  1. Start the app

  2. The Views are working correctly, when accessing with the url

    1. http://localhost:8000/admin1/user1/list
    2. http://localhost:8000/admin2/user2/list
  3. The navigation results in wrong url

    1. http://localhost:8000/admin2 --> Click on User2s -> Wrong URL http://localhost:8000/admin1/user2/list

Steps to reproduce the bug

from fastapi import FastAPI
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import declarative_base
from sqladmin import Admin, ModelView


# DB -------------------------------------------------------------------------
Base = declarative_base()
engine = create_engine(
    "sqlite:///example.db",
    connect_args={"check_same_thread": False},
)


class User1(Base):
    __tablename__ = "users1"

    id = Column(Integer, primary_key=True)
    name = Column(String)


class User2(Base):
    __tablename__ = "users2"

    id = Column(Integer, primary_key=True)
    name = Column(String)


Base.metadata.create_all(engine)  # Create tables

# Main App -------------------------------------------------------------------
app = FastAPI()

# Admin ----------------------------------------------------------------------
admin1 = Admin(app, engine, base_url="/admin1")
admin2 = Admin(app, engine, base_url="/admin2")


class UserAdmin1(ModelView, model=User1):
    column_list = [User1.id, User1.name]


class UserAdmin2(ModelView, model=User2):
    column_list = [User2.id, User2.name]


admin1.add_view(UserAdmin1)
admin2.add_view(UserAdmin2)

Expected behavior

No response

Actual behavior

No response

Debugging material

No response

Environment

Tested on Windows, I could also test on Linux

  • Windows 10
  • Python: 3.10.2
  • Sqladmin: 0.16.1

Additional context

No response

@hochstibe
Copy link
Author

It is not related to multiple fastapi applications. I simplified the code to 1 Fastapi with 2 Admin

@pkalemba
Copy link

pkalemba commented Nov 27, 2024

can you show what did you do to fix it?

edit:

I have identified the issue and plan to prepare a PR to address it.

Currently, running two instances of the application is not feasible due to URL conflicts caused by the hardcoded "admin:" prefix in the url_for function.

I will try to add an alias parameter to the Admin object. This alias would be utilized during URL generation to ensure unique and instance-specific URLs, preventing conflicts when multiple instances are deployed.

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

2 participants