killbill / killbill-analytics-plugin

Kill Bill plugin for financial reporting
https://killbill.io
Apache License 2.0
11 stars 32 forks source link

Exception while refreshing an account with a custom field #159

Closed reshmabidikar closed 1 year ago

reshmabidikar commented 1 year ago

An exception occurs while refreshing an account with a custom field.

Steps to reproduce:

  1. Create an account
  2. Create a custom field corresponding to the account
  3. Execute the Refresh account endpoint for this account
  4. The following exception occurs:
    
    2023-07-28T11:35:27,676+0000 lvl='WARN', log='ErrorPacket', th='http-nio-8080-exec-5', xff='', rId='', tok='', aRId='2053', tRId='1', Error: 1064-42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into analytics_account_fields (
    custom_field_record_id
    , name
    , fiel' at line 2
    2023-07-28T11:35:27,708+0000 lvl='ERROR', log='Err', th='http-nio-8080-exec-5', xff='', rId='', tok='', aRId='2053', tRId='1', execution of: PUT/3e62d708-e875-4e04-b938-ec048b9de573 resulted in exception
    Route:
      | Method | Path                                  | Source                                                                 | Name                            | Pattern      | Consumes | Produces |
      |--------|---------------------------------------|------------------------------------------------------------------------|---------------------------------|--------------|----------|----------|
      | PUT    | /3e62d708-e875-4e04-b938-ec048b9de573 | org.killbill.billing.plugin.analytics.http.AnalyticsAccountResource:81 | /AnalyticsAccountResource.doPut | /{accountId} | [*/*]    | [*/*]    |

Stacktrace: org.jooby.Err: Server Error(500) at org.jooby.internal.HttpHandlerImpl.handleErr(HttpHandlerImpl.java:589) at org.jooby.internal.HttpHandlerImpl.cleanup(HttpHandlerImpl.java:562) at org.jooby.internal.HttpHandlerImpl.handle(HttpHandlerImpl.java:504) at org.killbill.billing.plugin.core.JoobyServlet.service(JoobyServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.killbill.billing.osgi.ContextClassLoaderHelper$ClassLoaderInvocationHandler$1.execute(ContextClassLoaderHelper.java:146) at org.killbill.commons.profiling.Profiling.executeWithProfiling(Profiling.java:35) at org.killbill.billing.osgi.ContextClassLoaderHelper$ClassLoaderInvocationHandler.handleInvocation(ContextClassLoaderHelper.java:143) at org.killbill.commons.utils.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:91) at com.sun.proxy.$Proxy301.service(Unknown Source) at org.killbill.billing.osgi.http.OSGIServlet.serviceViaPlugin(OSGIServlet.java:89) at org.killbill.billing.osgi.http.OSGIServlet.doPut(OSGIServlet.java:67) at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) at org.killbill.billing.jaxrs.resources.PluginResource.serviceViaOSGIPlugin(PluginResource.java:218) at org.killbill.billing.jaxrs.resources.PluginResource.serviceViaOSGIPlugin(PluginResource.java:177) at org.killbill.billing.jaxrs.resources.PluginResource.doPUT(PluginResource.java:159) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:134) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:177) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:81) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:256) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244) at org.glassfish.jersey.internal.Errors.process(Errors.java:292) at org.glassfish.jersey.internal.Errors.process(Errors.java:274) at org.glassfish.jersey.internal.Errors.process(Errors.java:244) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:235) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684) at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:358) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205) at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:290) at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:280) at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:184) at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:89) at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85) at org.killbill.billing.server.security.TenantFilter.doFilter(TenantFilter.java:109) at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82) at org.killbill.billing.server.filters.ResponseCorsFilter.doFilter(ResponseCorsFilter.java:76) at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82) at ch.qos.logback.classic.helpers.MDCInsertingServletFilter.doFilter(MDCInsertingServletFilter.java:49) at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82) at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:121) at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:133) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:44) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:458) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:373) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:370) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.killbill.commons.metrics.servlets.InstrumentedFilter.doFilter(InstrumentedFilter.java:139) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: java.sql.SQLSyntaxErrorException: (conn=178) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into analytics_account_fields ( custom_field_record_id , name , fiel' at line 2 [statement:"create", located:"/! SET SQL_MODE=(SELECT CONCAT(@@SQL_MODE,',ANSI_QUOTES')) /; insert into analytics_account_fields ( custom_field_record_id , name , field_value , created_date , created_by , created_reason_code , created_comments , account_id , account_name , account_external_key , account_record_id , tenant_record_id , report_group ) values ( :customFieldRecordId , :name , :fieldValue , :createdDate , :createdBy , :createdReasonCode , :createdComments , :accountId , :accountName , :accountExternalKey , :accountRecordId , :tenantRecordId , :reportGroup );", rewritten:"/! SET SQL_MODE=(SELECT CONCAT(@@SQL_MODE,',ANSI_QUOTES')) /; insert into analytics_account_fields ( custom_field_record_id , name , field_value , created_date , created_by , created_reason_code , created_comments , account_id , account_name , account_external_key , account_record_id , tenant_record_id , report_group ) values ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? );", arguments:{ positional:{}, named:{tenantRecordId:1,accountName:'user-28July3',fieldValue:'value1',tableName:'analytics_account_fields',0:'analytics_account_fields',recordId:null,accountId:UUIDArgument{value=3e62d708-e875-4e04-b938-ec048b9de573},accountRecordId:2053,reportGroup:'default',2:PluginCallContext{accountId=3e62d708-e875-4e04-b938-ec048b9de573, callOrigin=EXTERNAL, comments=null, createdDate=2023-07-28T11:35:25.000Z, reasonCode=null, tenantId=9812a895-feac-4045-b1c0-768bdd6b13c1, updatedDate=2023-07-28T11:35:25.000Z, userName='killbill-analytics', userToken=212c698c-1cde-412d-8985-6c0af721686f, userType=SYSTEM},createdDate:DateTimeArgument{value=2023-07-28T08:31:21.000Z},createdBy:'admin',customFieldRecordId:111,name:'n1',createdComments:'null',accountExternalKey:'user-28July3',class:class org.killbill.billing.plugin.analytics.dao.model.BusinessAccountFieldModelDao,createdReasonCode:'null'}, finder:[]}] at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1340) at org.skife.jdbi.v2.Update.execute(Update.java:60) at org.skife.jdbi.v2.sqlobject.UpdateHandler$3.value(UpdateHandler.java:79) at org.skife.jdbi.v2.sqlobject.UpdateHandler.invoke(UpdateHandler.java:92) at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:178) at org.skife.jdbi.v2.sqlobject.SqlObjectInterceptor.intercept(SqlObjectInterceptor.java:44) at org.killbill.billing.plugin.analytics.dao.BusinessAnalyticsSqlDao$ByteBuddy$mcn5umjN.create(Unknown Source) at org.killbill.billing.plugin.analytics.dao.BusinessFieldDao.updateInTransaction(BusinessFieldDao.java:74) at org.killbill.billing.plugin.analytics.dao.BusinessFieldDao$1.inTransaction(BusinessFieldDao.java:55) at org.killbill.billing.plugin.analytics.dao.BusinessFieldDao$1.inTransaction(BusinessFieldDao.java:52) at org.skife.jdbi.v2.sqlobject.InTransactionWithIsolationLevelHandler$1.inTransaction(InTransactionWithIsolationLevelHandler.java:44) at org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.inTransaction(LocalTransactionHandler.java:188) at org.skife.jdbi.v2.tweak.transactions.DelegatingTransactionHandler.inTransaction(DelegatingTransactionHandler.java:86) at org.killbill.commons.jdbi.transaction.RestartTransactionRunner.inTransaction(RestartTransactionRunner.java:62) at org.killbill.commons.jdbi.transaction.RestartTransactionRunner.inTransaction(RestartTransactionRunner.java:85) at org.skife.jdbi.v2.BasicHandle.inTransaction(BasicHandle.java:344) at org.skife.jdbi.v2.sqlobject.InTransactionWithIsolationLevelHandler.invoke(InTransactionWithIsolationLevelHandler.java:39) at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:178) at org.skife.jdbi.v2.sqlobject.SqlObjectInterceptor.intercept(SqlObjectInterceptor.java:44) at org.killbill.billing.plugin.analytics.dao.BusinessAnalyticsSqlDao$ByteBuddy$mcn5umjN.inTransaction(Unknown Source) at org.killbill.billing.plugin.analytics.dao.BusinessAnalyticsDaoBase.executeInTransaction(BusinessAnalyticsDaoBase.java:44) at org.killbill.billing.plugin.analytics.dao.BusinessFieldDao.update(BusinessFieldDao.java:52) at org.killbill.billing.plugin.analytics.dao.AllBusinessObjectsDao.update(AllBusinessObjectsDao.java:66) at org.killbill.billing.plugin.analytics.api.user.AnalyticsUserApi.rebuildAnalyticsForAccount(AnalyticsUserApi.java:130) at org.killbill.billing.plugin.analytics.http.AnalyticsAccountResource.doPut(AnalyticsAccountResource.java:85) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.jooby.internal.mvc.MvcHandler.lambda$invoke$0(MvcHandler.java:278) at org.jooby.funzy.Throwing.fn(Throwing.java:2423) at org.jooby.funzy.Throwing.access$400(Throwing.java:39) at org.jooby.funzy.Throwing$Supplier.get(Throwing.java:145) at org.jooby.funzy.Try.apply(Try.java:691) at org.jooby.internal.mvc.MvcHandler.invoke(MvcHandler.java:269) at org.jooby.internal.mvc.MvcHandler.handle(MvcHandler.java:251) at org.jooby.internal.RouteImpl.handle(RouteImpl.java:280) at org.jooby.internal.RouteChain.next(RouteChain.java:262) at org.jooby.Route$Chain.next(Route.java:2164) at org.jooby.internal.HttpHandlerImpl.handle(HttpHandlerImpl.java:496) ... 97 common frames omitted Caused by: java.sql.SQLSyntaxErrorException: (conn=178) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into analytics_account_fields ( custom_field_record_id , name , fiel' at line 2 at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:282) at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:370) at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:137) at org.mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:840) at org.mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:779) at org.mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:698) at org.mariadb.jdbc.client.impl.StandardClient.execute(StandardClient.java:641) at org.mariadb.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:95) at org.mariadb.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:268) at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1334) ... 136 common frames omitted

reshmabidikar commented 1 year ago

Addressed in https://github.com/killbill/killbill-analytics-plugin/pull/160. Closing this issue.