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 { ...@@ -211,10 +211,13 @@ func (a *Adapter) SavePolicy(model model.Model) error {
} }
} }
if len(lines) > 0 {
_, err = a.db.Model(&lines). _, err = a.db.Model(&lines).
OnConflict("DO NOTHING"). OnConflict("DO NOTHING").
Insert() Insert()
return err return err
}
return nil
} }
// AddPolicy adds a policy rule to the storage. // AddPolicy adds a policy rule to the storage.
......
...@@ -221,6 +221,12 @@ func (s *AdapterTestSuite) TestSavePolicyClearPreviousData() { ...@@ -221,6 +221,12 @@ func (s *AdapterTestSuite) TestSavePolicyClearPreviousData() {
_, err := s.e.RemovePolicy(p) _, err := s.e.RemovePolicy(p)
s.Require().NoError(err) 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( s.assertPolicy(
[][]string{}, [][]string{},
s.e.GetPolicy(), 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