{"record":{"id":"fe9d91b776db91e0","repo":"pentaho/pentaho-kettle","slug":"attempting-to-create-pdi-repository-with-no-active","errorCode":null,"errorMessage":"Attempting to create PDI Repository with no Active PentahoSession. This is not allowed.","messagePattern":"Attempting to create PDI Repository with no Active PentahoSession\\. This is not allowed\\.","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/pur/core/src/main/java/org/pentaho/di/repository/utils/IRepositoryFactory.java","lineNumber":83,"sourceCode":"      this( new DefaultRepositoryFactory() );\n    }\n\n    public CachingRepositoryFactory( IRepositoryFactory delegate ) {\n      this.delegate = delegate;\n    }\n\n    @Override\n    public void setRepositoryId( String id ) {\n      delegate.setRepositoryId( id );\n    }\n\n    @Override\n    public Repository connect( String repositoryName ) throws KettleException {\n\n      IPentahoSession session = PentahoSessionHolder.getSession();\n      if ( session == null ) {\n        logger.debug( \"No active Pentaho Session, attempting to load PDI repository unauthenticated.\" );\n        throw new KettleException( \"Attempting to create PDI Repository with no Active PentahoSession. \"\n            + \"This is not allowed.\" );\n      }\n      ICacheManager cacheManager = PentahoSystem.getCacheManager( session );\n\n      String sessionName = session.getName();\n      try {\n        return (Repository) cacheManager.getOrCreateFromRegionCache( REGION, sessionName, () -> {\n          logger.debug( \"Repository not cached for user: \" + sessionName + \". Creating new Repository.\" );\n          try {\n            return delegate.connect( repositoryName );\n          } catch ( KettleException e ) {\n            throw new IllegalStateException( \"Failed to create repository for user: \" + sessionName, e );\n          }\n        } );\n      } catch ( IllegalStateException e ) {\n        if ( e.getCause() instanceof KettleException kettleException ) {\n          throw kettleException;\n        }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/pur/core/src/main/java/org/pentaho/di/repository/utils/IRepositoryFactory.java#L65-L101","documentation":"IRepositoryFactory.connect resolves the current Pentaho session via PentahoSessionHolder.getSession() before creating a PDI repository. If no session is active, the factory cannot authenticate or cache a repository for a user, so it throws a KettleException rather than proceeding unauthenticated. The debug log notes it will not attempt unauthenticated loading.","triggerScenarios":"Calling connect(repositoryName) (or testConnectNoSession, firstRepo, repo) outside a Pentaho web request / without an authenticated PentahoSession in the PentahoSessionHolder — e.g., from a standalone JVM, a background thread, or before login.","commonSituations":"Running PUR repository connection code in a command-line tool or test without initializing a Pentaho session; calling connect from a non-web thread where the session holder wasn't populated; forgetting to log into the Pentaho server first.","solutions":["Ensure a PentahoSession exists by logging into the Pentaho server or running within an authenticated request context.","Manually set a session via PentahoSessionHolder.setSession(...) before calling connect (e.g., a StandaloneSession with the appropriate user).","Use the explicit username/password repository connect API (Repository.connect(user, pass)) instead of the session-based factory when outside the Pentaho server.","If in a background job, propagate the caller's session to the worker thread."],"exampleFix":"// before\nRepository repo = repositoryFactory.connect(repositoryName); // no session\n// after\nPentahoSessionHolder.setSession(new StandaloneSession(\"admin\"));\nRepository repo = repositoryFactory.connect(repositoryName);","handlingStrategy":"try-catch","validationCode":"if (PentahoSessionHolder.getSession() == null) {\n  PentahoSessionHolder.setSession(new StandaloneSession(\"admin\"));\n}","typeGuard":null,"tryCatchPattern":"try { repo = factory.connect(name); }\ncatch (KettleException e) { if (e.getMessage().contains(\"no Active PentahoSession\")) { initSession(); } }","preventionTips":["Always connect within an authenticated Pentaho context","Set up a session explicitly in standalone/test code"],"tags":["pentaho","session","authentication","repository"],"backgroundTag":"authentication-required","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}