<@ULVA73B9P> What could account for the difference...
# ask-marvin
j
@Marvin What could account for the differences in the GitHub Credentials block between my prod and dev instances? The blocks appear to have different properties or methods based on error messages.
m
thought for 365.3 seconds
Short answer: you’re likely seeing two different versions of the GitHubCredentials block registered/used between your prod and dev workspaces/runtimes. In Prefect 3.x, block types are registered per workspace and blocks are instantiated using the version of the integration that’s installed in the environment where your code runs. If your prod/dev have different prefect-github package versions or were registered at different times, you’ll see different fields/methods and, consequently, different errors. Why this happens - Workspace-specific registration: Each Prefect Cloud workspace maintains its own “block type” registry. If you registered the GitHubCredentials block in prod at one time and in dev at another (with different versions of prefect-github installed), the UI schemas can differ across workspaces. - Local code defines behavior: When you call
GitHubCredentials.load("name")
in a flow, Prefect loads the stored data from the API but instantiates it with the class from your local environment. If dev has a newer/older prefect-github, you’ll see different properties/methods (e.g., a method being renamed or a field changed). - Schema drift: Minor changes like
access_token
vs
token
or method name changes can cause AttributeError/ValidationError differences across environments. How to confirm 1) Check your current workspace
Copy code
prefect cloud workspace ls
prefect cloud workspace set
2) Compare installed versions in prod vs dev - In each runtime/venv:
Copy code
pip show prefect prefect-github
(or print them from Python) 3) Compare block types and schemas in each workspace
Copy code
prefect blocks type ls
prefect blocks type inspect github-credentials
4) Inspect the specific block document(s)
Copy code
prefect blocks inspect github-credentials/<your-block-name>
How to align prod and dev - Standardize package versions in both environments:
Copy code
pip install "prefect==3.4.20" "prefect-github==<your-target-version>"
- Re-register the block types in each workspace from the environment with your target version. This updates the workspace’s block type schema to match the code you have installed:
Copy code
prefect block register -m prefect_github
# or, more narrowly
prefect block register -m prefect_github.credentials
- If you must load an older document with a newer class temporarily, you can bypass strict validation and then update/resave the block:
Copy code
from prefect_github import GitHubCredentials
creds = GitHubCredentials.load("my-github-creds", validate=False)
# update fields if needed, then creds.save(name="my-github-creds")
Next steps - If you can share: - The exact error messages (especially the missing attribute/property) - The output of
pip show prefect-github
in prod vs dev - The output of
prefect blocks type inspect github-credentials
from each workspace …we can pinpoint whether you’re hitting a method rename or a field change and suggest the minimal change (either re-registering or code updates). References - Blocks concepts (Prefect 3.x) - CLI: block commands - prefect-github integration
j
@Marvin In dev, the block is described as follows:
Copy code
GitHub Credentials                                                                                          
┌──────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Slug                                             │ github-credentials                                                                                                                              │
│ Block Type id                                    │ ce8bbe1c-11e6-4bd9-b455-b44efc1f82f6                                                                                                            │
│ Description                                      │ Block used to manage GitHub authentication                                                                                                      │
└──────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
                                                                                          Schema Properties                                                                                           
┌────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ token                  │ description: A GitHub personal access token (PAT).                                                                                                                        │
│                        │ format: password                                                                                                                                                          │
│                        │ title: Token                                                                                                                                                              │
│                        │ type: string                                                                                                                                                              │
│                        │ writeOnly: true                                                                                                                                                           │
│                        │                                                                                                                                                                           │
└────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
In prod, the schema is different:
Copy code
GitHub Credentials                                                                                          
┌──────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Slug                                             │ github-credentials                                                                                                                              │
│ Block Type id                                    │ c7c17b13-9609-4626-b985-c5d14a6f4949                                                                                                            │
│ Description                                      │ Block used to manage GitHub authentication                                                                                                      │
└──────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
                                                                                          Schema Properties                                                                                           
┌────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ token                  │ anyOf:                                                                                                                                                                    │
│                        │ - format: password                                                                                                                                                        │
│                        │   type: string                                                                                                                                                            │
│                        │   writeOnly: true                                                                                                                                                         │
│                        │ - type: 'null'                                                                                                                                                            │
│                        │ default: null                                                                                                                                                             │
│                        │ description: A GitHub personal access token (PAT).                                                                                                                        │
│                        │ title: Token                                                                                                                                                              │
│                        │                                                                                                                                                                           │
└────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
In prod, there is an existing github-credentials block that is part of the pull configuration for deployment code. It is important to not disturb this when getting the new block working.
m
thought for 57.6 seconds
Thanks for the concrete schemas — that explains the behavior. What you’re seeing is two different registered versions of the same block type (slug:
github-credentials
) across your dev and prod workspaces. In dev,
token
is required; in prod,
token
is optional (
anyOf: string|null
with a default of null). The different Block Type IDs confirm they’re distinct schemas that were registered at different times/with different
prefect-github
versions. Key implications - Workspace-local registration: Each Prefect Cloud workspace has its own registry. Registering or updating a block type in prod would change the prod schema for everyone in that workspace. Since you have a prod deployment that relies on a GitHub Credentials block for pull, you’re right to avoid disturbing it. - Runtime code matters: When you load a block in your flow, Prefect deserializes the stored data but instantiates it with whatever version of
prefect-github
is installed in that runtime. If methods/properties differ between versions, you’ll see different behaviors/errors even when loading the same block document. Safest path to get a new block working in prod without disturbing the existing one - Do NOT re-register block types in prod right now. - Create a new GitHub Credentials block document in prod under a new name and include a non-empty token value (even though the prod schema allows null). - Prefect Cloud UI: Blocks > GitHub Credentials > Create, give it a unique name (e.g.,
github-creds-new
) and set the PAT. - This will not touch the existing prod credentials block used by your deployment pull config. - In your flow code, load the new block and guard against schema differences:
Copy code
from prefect_github import GitHubCredentials

creds = GitHubCredentials.load("github-creds-new", validate=False)

# Ensure token is present; schema in prod allows null by default
token_val = getattr(creds, "token", None)
if not token_val:
    raise RuntimeError("GitHubCredentials token is missing in the prod block.")
# If the field is a SecretStr, get the raw value
if hasattr(token_val, "get_secret_value"):
    token_val = token_val.get_secret_value()

# Use creds as intended by your version of prefect-github from here
# (e.g., pass creds into your from_source/deploy logic or client creation)
- If you’re seeing attribute/method errors that imply the block’s API changed between versions, make your usage resilient:
Copy code
# Example pattern; method names can differ by version
# Prefer hasattr checks instead of assuming a specific method exists
if hasattr(creds, "get_client"):
    gh = creds.get_client()
elif hasattr(creds, "get_github_client"):
    gh = creds.get_github_client()
else:
    # As a last resort, build your own client using the token_val
    # e.g., PyGithub: Github(token_val)
    raise RuntimeError("No known client creation method on GitHubCredentials.")
I’m not asserting exact method names here because they can change by version; the point is to guard with
hasattr
to avoid breaking prod while you align environments. How to confirm and compare environments - Check your current workspace to ensure you’re looking at prod vs dev:
Copy code
prefect cloud workspace ls
prefect cloud workspace set
- Inspect block type and block documents:
Copy code
prefect blocks type ls
prefect blocks type inspect github-credentials
prefect blocks inspect github-credentials/<block-name>
- Compare installed versions in your dev and prod runtimes:
Copy code
pip show prefect prefect-github
Longer-term options (when you’re ready) - Standardize versions: Pin the same
prefect
and
prefect-github
versions in dev and prod runtimes. If you need different versions for different workloads, run them in separate worker images/work pools so you don’t impact the deployment that performs code pulls. - If/when you want schemas unified in prod, plan a maintenance window and re-register the block type from your chosen image: ``` prefect block register -m prefect_github # or specifically
prefect block register -m prefect_github.credentials ``` Re-registration updates the workspace schema for that type; existing block documents remain, but validation rules in UI and at load time can change, so test first. If you can share the exact method/attribute errors you’re seeing in prod vs dev, I can recommend the minimal code changes that work across both versions. Helpful references - Blocks concepts: Prefect 3.x Blocks - CLI block commands: prefect blocks CLI - prefect-github integration: prefect-github