netfishers-onl / Netshot

Network Configuration and Compliance Management
http://www.netfishers.onl/netshot
249 stars 60 forks source link

500 HTTP error while trying to edit policy through route PUT /policies/{id} #310

Closed djoproject closed 2 months ago

djoproject commented 5 months ago

Description

While trying to update an existing policy through the REST API, it always results into a 500 HTTP error.

Route: /policies/{id} Method: PUT Netshot version: v0.19.4

How to reproduce

Through the Web-UI:

  1. Go to Compliance page
  2. Click on Create policy
  3. fill a name, no need of groups, then click on add
  4. find the new created policy on the left column, click on edit
  5. Change the name then click on save
  6. An error label appears Error: Unknown

Screenshot_2024-06-25_11-34-12

Relevant logs

2024-06-25T09:28:48.446483676Z 2024-06-25 09:28:48,444 ERROR [grizzly-http-server-3] RestService: Uncaught exception thrown by REST service
2024-06-25T09:28:48.446674270Z com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: onl.netfishers.netshot.compliance.Policy.rules, could not initialize proxy - no Session (through reference chain: onl.netfishers.netshot.compliance.Policy["ruleCount"])
2024-06-25T09:28:48.446697816Z  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
2024-06-25T09:28:48.446708229Z  at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
2024-06-25T09:28:48.446717055Z  at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:323)
2024-06-25T09:28:48.446725865Z  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:778)
2024-06-25T09:28:48.446736608Z  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:183)
2024-06-25T09:28:48.446746076Z  at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:502)
2024-06-25T09:28:48.446755438Z  at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341)
2024-06-25T09:28:48.446799768Z  at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1572)
2024-06-25T09:28:48.446811081Z  at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1061)
2024-06-25T09:28:48.446820352Z  at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:620)
2024-06-25T09:28:48.446831337Z  at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:242)
2024-06-25T09:28:48.446841332Z  at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:227)
2024-06-25T09:28:48.446850633Z  at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
2024-06-25T09:28:48.446859543Z  at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:85)
2024-06-25T09:28:48.446868722Z  at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
2024-06-25T09:28:48.446883222Z  at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:61)
2024-06-25T09:28:48.446893026Z  at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
2024-06-25T09:28:48.446902671Z  at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1116)
2024-06-25T09:28:48.446911823Z  at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:649)
2024-06-25T09:28:48.446920502Z  at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:380)
2024-06-25T09:28:48.446929452Z  at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:370)
2024-06-25T09:28:48.446938499Z  at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
2024-06-25T09:28:48.446947682Z  at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
2024-06-25T09:28:48.446956503Z  at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
2024-06-25T09:28:48.446965203Z  at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
2024-06-25T09:28:48.446974339Z  at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
2024-06-25T09:28:48.447042629Z  at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
2024-06-25T09:28:48.447059000Z  at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
2024-06-25T09:28:48.447073973Z  at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:235)
2024-06-25T09:28:48.447086987Z  at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684)
2024-06-25T09:28:48.447099495Z  at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
2024-06-25T09:28:48.447135634Z  at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
2024-06-25T09:28:48.447153775Z  at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:358)
2024-06-25T09:28:48.447168241Z  at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311)
2024-06-25T09:28:48.447182805Z  at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
2024-06-25T09:28:48.447196334Z  at org.glassfish.grizzly.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:124)
2024-06-25T09:28:48.447212330Z  at org.glassfish.grizzly.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:83)
2024-06-25T09:28:48.447227560Z  at org.glassfish.grizzly.servlet.ServletHandler.doServletService(ServletHandler.java:202)
2024-06-25T09:28:48.447242981Z  at org.glassfish.grizzly.servlet.ServletHandler.service(ServletHandler.java:149)
2024-06-25T09:28:48.447261507Z  at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:200)
2024-06-25T09:28:48.447278256Z  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
2024-06-25T09:28:48.447293465Z  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
2024-06-25T09:28:48.447308929Z  at java.base/java.lang.Thread.run(Thread.java:833)
2024-06-25T09:28:48.447323246Z Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: onl.netfishers.netshot.compliance.Policy.rules, could not initialize proxy - no Session
2024-06-25T09:28:48.447337634Z  at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:614)
2024-06-25T09:28:48.447354955Z  at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:218)
2024-06-25T09:28:48.447403532Z  at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:162)
2024-06-25T09:28:48.447439558Z  at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:168)
2024-06-25T09:28:48.447455098Z  at onl.netfishers.netshot.compliance.Policy.getRuleCount(Policy.java:118)
2024-06-25T09:28:48.447469243Z  at jdk.internal.reflect.GeneratedMethodAccessor122.invoke(Unknown Source)
2024-06-25T09:28:48.447482401Z  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2024-06-25T09:28:48.447495534Z  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
2024-06-25T09:28:48.447510501Z  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688)
2024-06-25T09:28:48.447524855Z  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
2024-06-25T09:28:48.447540380Z  ... 39 common frames omitted

Notes

SCadilhac commented 2 months ago

Should be fixed after d268054b410e93405cbc0a891593a5cc3b08fbd6