Skip to content

Upgrading from 3.x

CascadeUI 4.0.0 changes how a few things look and behave, and it refuses mistakes earlier: most input that 3.14.2 accepted and then misread now raises where it is written, naming the fix. This page sorts the changes by how you meet them, with what to do for each. The Changelog has every change in full.

Before You Upgrade

CascadeUI 4.0.0 needs Python 3.10 or newer and discord.py 2.7 or newer, as 3.14.2 did.

  1. Install it with the extras you use, such as pip install --upgrade "pycascadeui[postgres]", and raise any <4.0 cap in your requirements or constraints files.
  2. Run your tests, or start the bot and open each panel once. Almost every change below raises the first time the code it affects runs, and most raise when a class is defined, so importing your cogs finds them.
  3. Run once with deprecation warnings shown, since Python hides them outside your main script: python -W default::DeprecationWarning bot.py. Each warning names what to change before 5.0.0.

What Changes Without an Error

These change what a person sees or what your code gets back, and nothing raises. Read this list first.

Change What to do
A person's second click on a button is dropped while their first click on it is still running and has had no reply For a button where every quick click counts (a counter, a stepper), pass allow_double_click=True
A select pick whose callback sends nothing is answered with the view's current render, so a pick the callback only stored goes back to the placeholder Draw the pick: mark the chosen option default=True and call refresh(). A WARNING names the select when the answer shows it unmarked
on_error() runs before the click is acknowledged An override that replied only through interaction.followup.send() answers through interaction.response or respond() instead
A screen pushed from a panel with no owner has no owner When the screen is about the person who clicked, name them: push(MyStats, interaction, user_id=interaction.user.id)
regex() matches the whole value End a pattern that checks how a value begins with .*, as in r"https?://.*"
RetryConfig(max_retries=N) retries N times, so with_retry makes up to N + 1 calls Lower max_retries by one to keep the old count
reload() held back by the throttle returns RenderOutcome.POSTPONED, not DEFERRED Add POSTPONED where code compares a reload to DEFERRED
On a class that sets timeout in its body, MyView.timeout is a property Read the timeout from an instance: view.timeout
@cascade_reducer returns the decorated function unchanged Drop an await on a direct call to a plain def reducer
The inspector's computed values carry the library's prefix (cascadeui_total_views) Read them under the new names
After a bot closes, setup_middleware() replaces each middleware it installed with the new one of its kind Pass the same object to keep a middleware's own state
A scoped-state id given as a string of digits stands for its number, so "042" and 42 read one slice Move data a zero-padded id wrote before the upgrade, which stays under its old key
An instance_limit under the default instance_scope = "user_guild" counts a person's DMs as one place, so a second panel there is refused or replaces the first Raise instance_limit where a person may keep more than one panel open in DMs
on_tab_switched() and on_page_changed() do not run for a click on the open tab, or a jump to the page already shown Nothing, unless an override counted those clicks: the hooks now report only a move
A subscribe() callback runs only once the selected value changes from its value at subscribe time Read the starting value yourself after subscribing, if the callback needs it
REGISTRY_PRUNED goes out only when a row was deleted Read what was pruned from the action, or prune_registry()'s return, rather than waiting for an empty one
dispatch() raises its exceptions without logging them first Log the exception where you catch it, if you relied on the ERROR line
A level or filter set on the cascadeui.views.base logger reaches only the construction code, since each view module now logs under its own name Set it on cascadeui.views
The library reads a view's _bot as its client, as the new bot property stores it Keep anything else under another name, and keep the bot in self.bot

What Your Panels Look Like

Some panels draw differently. Nothing in your code needs to change unless a test reads the old layout.

Panel In 4.0.0
FormLayoutView One card: each group under its heading with its own Edit button, a select of up to five short options as a row of buttons, a boolean as an On/Off toggle, and Submit inside the card. A test that clicked a select or a Yes or No button clicks the option button with that label, or the toggle (form:toggle:<id>)
WizardLayoutView One card: the step's name over its progress bar, a line, then the step, when the step returns one card or components with none. A test that read the bar as the header card's last child reads its second
PaginatedLayoutView A page given as text, the "Loading..." page, and the empty page are drawn as a card() in the theme's accent
LeaderboardLayoutView A board with no entries keeps its masthead inside the empty-state card, which takes card_color
Ephemeral panels The Continue button appears 13.5 minutes after the panel was last used and brings the same panel back in place
V1 patterns sent with content= The text goes out with the view's own embed, where it went out alone until a click
Progress bars Round halves up and show a full bar only when done: 5 of 8 reads 63%
divider() and gap() Follow the view's separator_spacing wherever they were built, and a theme changed at runtime
Pager arrows given an emoji Show the emoji alone, without the default arrow beside it

Errors When a Class Is Defined

These raise as your cogs are imported, each naming the class and the fix.

What raises What to do
A class attribute of the wrong type (owner_only = 1, instance_limit = "3") raises TypeError, where it raised ValueError, and one on a plain mixin is checked too Fix the value. Code that catches ValueError from these catches TypeError too
A method named like one of the library's private methods, in a shape the library cannot call (an async def _disarm(self)) Rename the method. Any other such name warns with PrivateNameWarning
An override of a hook the library runs after an event that cannot take its arguments, most often on_validation_failed(self, step_index, error) Write the signature the message gives: on_validation_failed(self, step_index, error, interaction)
An async def override of a hook a pattern calls while it builds: build_extra_items(), the menu's build_header(), a tab view's build_tab_rows(), the wizard's build_progress_header(), and others Make it a plain def, and load async data in on_load()
_build_refresh_button() or _safe_defer() defined without the new name Rename to build_refresh_button() or safe_defer()
build_reopen_view() defined Move its work into on_load(), which runs at every Continue; the Continue now resumes the same view
create_discord_component() on a modal input, or create_discord_components() on a CompositeComponent, defined Pass inputs to Modal(inputs=[...]), and add a composite's components with add_component()
reattach_persistent_views() or reseed_registry_mirror() on a PersistenceManager subclass, or finalize_batch() on an UndoMiddleware subclass, defined Drop the override: the library no longer calls these names, and a batch's exit writes its own undo entry
A persistent view's timeout set to a number Remove it: a persistent view does not time out (None and 0 are accepted)
session_class_key on a mixin Set it on the class itself
refresh_warning_seconds = None Give it a number of seconds
A roles panel's two categories whose names give one slug, or an on_role_* hook written as a plain method Give one category a key=, and make each hook a classmethod or staticmethod
A DynamicPersistentButton whose template groups its __init__ does not take Match the __init__ to the template's groups

Errors Where You Build or Call Something

These raise when the code runs, at the call that holds the mistake. Where 3.14.2 raised ValueError for a value of the wrong type, 4.0.0 raises TypeError.

Views and Navigation

What raises What to do
A view whose __init__ never calls super().__init__() Call it
view.user_id or view.guild_id assigned something that is not an id Assign an int or a Member, Guild, or other object with an .id
view.bot assigned something that is not a discord.Client Assign the bot. In tests, use stub_client() or MagicMock(spec=commands.Bot)
send() through a context whose own send() returns no message raises RuntimeError Return the posted message from that send()
push() or pop() whose new screen Discord refuses (an embed past its limits) Fix the screen's content; the error reaches on_error() like any other
A persistent panel whose seed_initial_state() builds a button with no custom_id Give the button a custom_id

Components and Callbacks

What raises What to do
A callback that cannot be called, or a method called by mistake (callback=self.on_click()) Pass the method without the ()
A callback, builder, validator, or hook that cannot take the arguments it will be given Write the signature the message gives
owner_only or allow_double_click that is not a bool Pass True or False
A select whose min_values is above its max_values or its options Fix the bounds
A str given where a list belongs: pages=, a region's items, cycle_button(values=), ToggleGroup(options=) Pass a list
Modal.submit() given a choice value no option has, or a select's pick not in a list Pass the option's value ("yes", not True), in a list for a select or a checkbox group
A single-select choice_row given a callable selected Pass the selected value, or use multi=True to read a callable
A DynamicPersistentButton built with an id its template matches only at the start, or one another class's template also matches Make the template match the whole id, and give each class ids of its own. Buttons already posted keep working
A custom_id that is not a str on a builder or Modal, ToggleGroup with no options, with_cooldown(seconds=) below 0, or an emoji_grid axis label given as a str other than "alpha" or "numeric" Fix the argument, as the message says. Custom axis labels go in a list

Patterns

What raises What to do
A wizard, tab view, or menu given no steps, tabs, or categories, or given them only in the class body, where the view does not read them Pass at least one when the view is built
A roles panel whose class body lists no categories List at least one RoleCategory there
A role button with neither a label nor an emoji Give it one
build_tab_rows() leaving a tab out, or adding a button that is not a tab Put every tab in a row, and other buttons in build_extra_items()
A page a paginator cannot show or draw, or a formatter that returns None Return an Embed, text, or a dict of embed, embeds, or content (V1), or components or text (V2)
A form field dict with no id, two fields sharing an id, or a default the field cannot hold Fix the field
A key a letter or two off one the library reads ("requried", "validate", "accent_color") Spell the key as the message gives it
set_field_error() given an id the form does not have, or a message that is not a str Use one of the ids the message lists, and pass text
set_class_attribute() asking a paginator for buttons a page has no room for Put less on each page, or leave the setting as it is

State, Persistence, and Validation

What raises What to do
An action type that is not a non-empty string Name the action with a string
store.persistence_manager.reattach_persistent_views() or reseed_registry_mirror(), PersistenceMiddleware.flush_all() or close(), UndoMiddleware.finalize_batch(), or a batch's add_entry() or add_undo_record() called (AttributeError) Call reattach(), which returns the same summary, and store.persistence_manager.flush_all() or close()
state["sessions"][session_id]["history"] read (KeyError), or reduce_navigation_replace imported Listen for NAVIGATION_REPLACE, which still goes out, and keep your own record
set_scoped() given a value that is not a dict Pass a dict
merge_scoped() or a SCOPED_UPDATE with an unknown scope or a missing id. Inside a reducer the store logs it at ERROR, naming the action Fix the scope's name, or pass the id it needs
register_hook() given a name other than on_flush or on_error, or subscribe(action_filter=) given a str or a mapping Use one of the two hook names, and pass a set of action types
Two @computed functions registering one name, or an async one Rename one, and make the function synchronous
A slot_property assigned Change the value in a reducer, through dispatch()
access_slot() given a key of None Leave the key out to read the whole slot
A scoped-state id that is not a Discord id, or iter_scoped() given a filter its scope does not hold Pass the id, or drop the filter
undo() or redo() without UndoMiddleware installed await setup_middleware(UndoMiddleware())
A middleware that stops one of the library's own records, such as VIEW_CREATED Call next_fn for every action you do not mean to stop
has_middleware(middleware_cls=...) Pass the class by position, or as middleware=
A schema migrator that would never run Drop it; a change to what a panel stores takes register_kwargs_migrator()
A ttl_days slot policy on a backend that cannot expire rows Drop ttl_days, or use a backend with Capability.TTL_INDEX
A validator factory given an argument of the wrong kind (min_length("3")), or validate_fields() given a field with no "id" Fix the argument
Pairs that repeat a key in tabs= or Theme(styles=) Give each tab or style once
Theme with no name or a separator_spacing other than "small" or "large", set_default_theme() naming no theme or given name= by keyword, or register_theme() given a name Give Theme its name first, pass set_default_theme() the name by position, and pass register_theme() the Theme
slugify() or is_emoji() given a value that is not text Pass a str
A misspelled setup_logging() preset, a wrong RetryConfig argument, with_retry(5), or safe_execute(fetch) Fix the argument, as the message says

In Your Tests

Change What to do
A choice that Modal.submit() leaves out keeps the options marked as its defaults, as the dialog opens on them, where it read as no answer Give the choice in values when the test means another answer
On stub_interaction(), a deferred reply posts a "thinking" message, and a followup sent while it stands becomes the original response and keeps the defer's visibility, as on Discord Read that followup as the original response

Code You Can Delete

  • An on_restore() that only called build_ui() so a restored panel had its controls: the restore draws an empty view from build_ui() itself.
  • An on_leaderboard_empty() override that only kept the masthead and the message in one card: the empty board draws that way now.
  • guild, type, message, or data set by hand on stub_interaction(): it carries them.

Deprecated Names

These keep working through 4.x and warn with a DeprecationWarning when a class that uses them is defined. They are removed in 5.0.0.

Old name New name
_build_extra_items() build_extra_items()
_build_category_item(), _build_category_button() build_category_item(), build_category_button()
_build_category_card() on a menu build_menu_card()
_build_tab_rows() build_tab_rows()
_build_progress_header() build_progress_header()
_freeze_components() freeze_components()
_extract_page() on a V1 paginator page_kwargs()

The roles pattern (RolesLayoutView, PersistentRolesLayoutView, and RoleCategory) is deprecated too. To keep a role panel, build it from a PersistentLayoutView whose buttons add or remove the role in their callback, with a DynamicPersistentButton so the buttons keep working after a restart. v2_persistence.py shows the shape.