# Permission denied when trying to access artifact versions in pytorch lightning callback

**URL:** <https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780>\
**Category:** W&B Help\
**Tags:** artifacts, wandb, pytorch\
**Created:** [July 24, 2023, 9:30am UTC](https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780 "2023-07-24T09:30:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![develop](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@develop](https://community.wandb.ai/u/develop)\
**Post date:** [July 24, 2023, 9:30am UTC](https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780/1 "2023-07-24T09:30:39Z")

</div>

I’m trying to access artifact versions in pytorch lightning callback and I’m still getting `wandb.errors.CommError: Permission denied to access (...)` exception. However, when I run the same code from standalone script or even in the same codebase but going step by step using debugger it works fine. I suppose it’s somehow caused by the fact it’s ran from the callback. How can I fix it?  
The minimum callback code below:

```auto
import pytorch_lightning as pl
import wandb

class MyCallback(pl.callbacks.Callback):
    def __init__ (
        self,
    ) -> None:
        self._artifact_type = "my_type"
        self._artifact_name = "my_name"
        self._api = wandb.Api(
            overrides={"entity": wandb.run.entity, "project": wandb.run.project}
        )

    def on_validation_end(
        self, trainer: pl.Trainer, pl_module: pl.LightningModule
    ) -> None:
        self._log_artifact(pl_module)
        self._remove_old_versions()

    def _log_artifact(self, pl_module: pl.LightningModule) -> None:
        ...

    def _remove_old_versions(self) -> None:
        for v in self._api.artifact_versions(self._artifact_type, self._artifact_name):
            if "latest" not in v.aliases:
                v.delete()

```

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [July 27, 2023, 5:21pm UTC](https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780/2 "2023-07-27T17:21:29Z")

</div>

Hi @develop, the fact that this does work in debugging mode leads me to think this may be an issue with the lazy loading the API uses. Could you try to reinstantiate the wandb api in your `remove_old_versions(self)`function? For example:  
`self._api = wandb.Api(overrides={"entity": wandb.run.entity, "project": wandb.run.project}`

Before you iterate through the Artifact versions that exist?

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [August 3, 2023, 6:59pm UTC](https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780/3 "2023-08-03T18:59:23Z")

</div>

Hi @develop, I wanted to follow up and see if you had a chance to try this out?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [October 2, 2023, 6:59pm UTC](https://community.wandb.ai/t/permission-denied-when-trying-to-access-artifact-versions-in-pytorch-lightning-callback/4780/4 "2023-10-02T18:59:44Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
