Giter Site home page Giter Site logo

Comments (3)

dolamroth avatar dolamroth commented on May 21, 2024 1

Overriding action delete in the following way indeed helps

    async def delete_action(self, request: Request, pks: List[Any]) -> str:
        try:
            affected_rows = await self.delete(request, pks)
        except SQLAlchemyError as exc:
            raise ActionFailed(str(exc))
        return "{} items were successfully deleted".format(affected_rows)

Maybe it would be better to override default starlette_admin.contrib.sqla.view.ModelView.delete_action to wrap any sqlalchemy.exc.SQLAlchemyError with re-raising ActionFailed, what do you think? I could provide a PR.

from starlette-admin.

jowilf avatar jowilf commented on May 21, 2024

ModelView.delete method is used as action, You need to raise ActionFailed(msg) to display a meaningfully error. More info https://jowilf.github.io/starlette-admin/tutorial/batch-actions/

-> To be added in the documentation

from starlette-admin.

dolamroth avatar dolamroth commented on May 21, 2024

There still seems to be a bug with "delete" on item page /admin/{entity}/detail/{id}.

After trying to delete an instance, I get empty modal window (only icon, but no text).
However, in browser console there is JSON response

{"msg": "(sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class 'asyncpg.exceptions.ForeignKeyViolationError'>..."}

From what I see in JS handler, text is not being set in modal window.

function() {
  $("#modal-delete").modal('hide');
  $("#modal-loading").modal('show');
  fetch("......", {
    method: "POST",
  }).then(async response => {
    if (response.ok) {
      await new Promise(r => setTimeout(r, 500));
      $("#modal-loading").modal('hide')
      window.location.replace(".........")
    } else
      return Promise.reject();

  }).catch(async (error) => {
    await new Promise(r => setTimeout(r, 500));
    $("#modal-loading").modal('hide')
    $("#modal-error").modal('show');
  });
}

from starlette-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.