Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-9790

Repository and Pull Request deletion fails due to Database error

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Highest
    • 5.1.0, 5.0.2
    • 5.0.0, 5.0.1
    • Enterprise
    • None

    Description

      Summary

      When attempting to delete a repository or a pull request that has comment activities which were created before 5.0 was installed, the deletion fails.

      Steps to Reproduce

      1. Install Bitbucket 4.14
      2. Create a pull request and add a comment to the diff
      3. Upgrade to Bitbucket 5.0
      4. Delete the repository the pull request is in

      Expected Results

      The repository is deleted

      Actual Results

      The repository is not deleted. An error is shown and the following stack appears in the logs:

      2017-05-23 13:24:27,326 WARN  [http-nio-7990-exec-8] admin @1S1B560x804x86x0 ohu5hs 0:0:0:0:0:0:0:1 "DELETE /projects/AWESOMEFROZENSALAD35194/repos/linux HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 23503, SQLState: 23503
      2017-05-23 13:24:27,327 ERROR [http-nio-7990-exec-8] admin @1S1B560x804x86x0 ohu5hs 0:0:0:0:0:0:0:1 "DELETE /projects/AWESOMEFROZENSALAD35194/repos/linux HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper Referential integrity constraint violation: "FK_STA_PR_DIFF_COM_ANC_PR: PUBLIC.STA_PR_DIFF_COMMENT_ANCHOR FOREIGN KEY(PR_ID) REFERENCES PUBLIC.STA_PULL_REQUEST(ID) (1)"; SQL statement:
      delete from sta_pull_request where to_repository_id=? [23503-176]
      2017-05-23 13:24:27,335 ERROR [http-nio-7990-exec-8] admin @1S1B560x804x86x0 ohu5hs 0:0:0:0:0:0:0:1 "DELETE /projects/AWESOMEFROZENSALAD35194/repos/linux HTTP/1.1" c.a.s.i.p.DefaultPullRequestService AWESOMEFROZENSALAD35194/linux[16]: Pull requests could not be cleaned up on repository deletion
      org.hibernate.exception.ConstraintViolationException: could not execute statement
      	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
      	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
      	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
      	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
      	at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:90)
      	at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:59)
      	at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:110)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:437)
      	at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:374)
      	at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1510)
      	at org.hibernate.query.internal.AbstractProducedQuery.doExecuteUpdate(AbstractProducedQuery.java:1526)
      	at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1504)
      	at com.atlassian.stash.internal.pull.HibernatePullRequestDao.deleteByToRepository(HibernatePullRequestDao.java:183)
      	at com.atlassian.stash.internal.pull.DefaultPullRequestService.cleanup(DefaultPullRequestService.java:1231)
      	at com.atlassian.stash.internal.pull.DefaultPullRequestService.onRepositoryDeleteRequested(DefaultPullRequestService.java:684)
      	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:40)
      	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:38)
      	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
      	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:88)
      	at com.atlassian.event.internal.LockFreeEventPublisher$Publisher.dispatch(LockFreeEventPublisher.java:222)
      	at com.atlassian.event.internal.LockFreeEventPublisher.publish(LockFreeEventPublisher.java:95)
      	at com.atlassian.stash.internal.event.TransactionAwareEventPublisher.internalPublish(TransactionAwareEventPublisher.java:155)
      	at com.atlassian.stash.internal.event.TransactionAwareEventPublisher.publish(TransactionAwareEventPublisher.java:99)
      	at com.atlassian.stash.internal.repository.DefaultRepositoryService.fireRepositoryDeletionRequested(DefaultRepositoryService.java:711)
      	at com.atlassian.stash.internal.repository.DefaultRepositoryService.lambda$delete$1(DefaultRepositoryService.java:186)
      	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
      	at com.atlassian.stash.internal.repository.DefaultRepositoryService.delete(DefaultRepositoryService.java:185)
      	at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
      	at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
      	at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
      	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
      	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
      	at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
      	at com.atlassian.stash.internal.rest.repository.RepositoryResource.deleteRepository(RepositoryResource.java:168)
      	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
      	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
      	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
      	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
      	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.stash.internal.spring.security.StashAuthenticationFilter.doFilter(StashAuthenticationFilter.java:88)
      	at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doInsideSpringSecurityChain(BeforeLoginPluginAuthenticationFilter.java:112)
      	at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:75)
      	at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:94)
      	at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:67)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:94)
      	at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:67)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.plugin.connect.plugin.auth.user.ThreeLeggedAuthFilter.doFilter(ThreeLeggedAuthFilter.java:109)
      	at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:32)
      	at com.atlassian.analytics.client.filter.DefaultAnalyticsFilter.doFilter(DefaultAnalyticsFilter.java:38)
      	at com.atlassian.analytics.client.filter.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:39)
      	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
      	at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doBeforeBeforeLoginFilters(BeforeLoginPluginAuthenticationFilter.java:90)
      	at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:73)
      	at com.atlassian.stash.internal.request.DefaultRequestManager.doAsRequest(DefaultRequestManager.java:89)
      	at com.atlassian.stash.internal.hazelcast.ConfigurableWebFilter.doFilter(ConfigurableWebFilter.java:38)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.lang.Thread.run(Thread.java:745)
      	... 344 frames trimmed
      Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK_STA_PR_DIFF_COM_ANC_PR: PUBLIC.STA_PR_DIFF_COMMENT_ANCHOR FOREIGN KEY(PR_ID) REFERENCES PUBLIC.STA_PULL_REQUEST(ID) (1)"; SQL statement:
      delete from sta_pull_request where to_repository_id=? [23503-176]
      	at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
      	at org.h2.message.DbException.get(DbException.java:178)
      	at org.h2.message.DbException.get(DbException.java:154)
      	at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:427)
      	at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:444)
      	at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:319)
      	at org.h2.table.Table.fireConstraints(Table.java:909)
      	at org.h2.table.Table.fireAfterRow(Table.java:927)
      	at org.h2.command.dml.Delete.update(Delete.java:101)
      	at org.h2.command.CommandContainer.update(CommandContainer.java:79)
      	at org.h2.command.Command.executeUpdate(Command.java:254)
      	at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:158)
      	at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:144)
      	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
      	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
      	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
      	... 59 common frames omitted
      

      Workaround

      Manually drop the foreign key constraint FK_STA_PR_DIFF_COM_ANC_PR
       

      Attachments

        Issue Links

          Activity

            People

              fhaehnel Felix
              fhaehnel Felix
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: