@@ -125,6 +125,10 @@ func (pr *dbPackageRevision) UpdateLifecycle(ctx context.Context, newLifecycle p
125125 _ , span := tracer .Start (ctx , "dbPackageRevision::UpdateLifecycle" , trace .WithAttributes ())
126126 defer span .End ()
127127
128+ if pr .repo == nil {
129+ return fmt .Errorf ("cannot update lifecycle for package revision %s: no associated repository" , pr .KubeObjectName ())
130+ }
131+
128132 if pr .lifecycle == porchapi .PackageRevisionLifecycleProposed && newLifecycle == porchapi .PackageRevisionLifecyclePublished {
129133 if err := pr .publishPR (ctx , newLifecycle ); err != nil {
130134 pr .pkgRevKey .Revision = 0
@@ -142,6 +146,15 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi.
142146 _ , span := tracer .Start (ctx , "dbPackageRevision::GetPackageRevision" , trace .WithAttributes ())
143147 defer span .End ()
144148
149+ if pr == nil {
150+ return nil , fmt .Errorf ("invalid package revision: nil object" )
151+ }
152+
153+ if pr .repo == nil {
154+ klog .Warningf ("package revision %+v has nil repository, skipping" , pr .Key ())
155+ return nil , fmt .Errorf ("package revision %s has no associated repository (may be deleted or not yet cached)" , pr .KubeObjectName ())
156+ }
157+
145158 readPR , err := pkgRevReadFromDB (ctx , pr .Key (), false )
146159 if err != nil {
147160 if pr .GetMeta ().DeletionTimestamp != nil || strings .Contains (err .Error (), "sql: no rows in result set" ) {
@@ -152,14 +165,14 @@ func (pr *dbPackageRevision) GetPackageRevision(ctx context.Context) (*porchapi.
152165 }
153166 }
154167
155- _ , upstreamLock , _ := pr .GetUpstreamLock (ctx )
156- _ , selfLock , _ := pr .GetLock (ctx )
168+ _ , upstreamLock , _ := readPR .GetUpstreamLock (ctx )
169+ _ , selfLock , _ := readPR .GetLock (ctx )
157170 kf , _ := readPR .GetKptfile (ctx )
158171
159172 status := porchapi.PackageRevisionStatus {
160173 UpstreamLock : repository .KptUpstreamLock2APIUpstreamLock (upstreamLock ),
161174 SelfLock : repository .KptUpstreamLock2APIUpstreamLock (selfLock ),
162- Deployment : pr .repo .deployment ,
175+ Deployment : readPR .repo .deployment ,
163176 Conditions : repository .ToAPIConditions (kf ),
164177 }
165178
0 commit comments