Commit 88e55925 authored by khoipham's avatar khoipham

Fix error can't bulk-insert empty slice []*pgadapter.CasbinRule

parent 7223ed5c
......@@ -211,10 +211,13 @@ func (a *Adapter) SavePolicy(model model.Model) error {
}
}
_, err = a.db.Model(&lines).
OnConflict("DO NOTHING").
Insert()
return err
if len(lines) > 0 {
_, err = a.db.Model(&lines).
OnConflict("DO NOTHING").
Insert()
return err
}
return nil
}
// AddPolicy adds a policy rule to the storage.
......
......@@ -221,6 +221,12 @@ func (s *AdapterTestSuite) TestSavePolicyClearPreviousData() {
_, err := s.e.RemovePolicy(p)
s.Require().NoError(err)
}
policies = s.e.GetGroupingPolicy()
policies = append(policies[:0:0], policies...)
for _, p := range policies {
_, err := s.e.RemoveGroupingPolicy(p)
s.Require().NoError(err)
}
s.assertPolicy(
[][]string{},
s.e.GetPolicy(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment