Skip to content

Conversation

@bckohan
Copy link
Contributor

@bckohan bckohan commented Dec 8, 2025

This PR replaces #65

It needs some more work. I would like it to support casting across multiple levels of hierarchy.

The discussion in #65 and the details of this long standing Django ticket should be considered.

Fixes #296

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.75%. Comparing base (1d1d2d9) to head (6cd80a3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   76.44%   76.75%   +0.30%     
==========================================
  Files          22       22              
  Lines        1350     1368      +18     
  Branches      211      214       +3     
==========================================
+ Hits         1032     1050      +18     
  Misses        250      250              
  Partials       68       68              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a create_from_super method to the PolymorphicManager class that enables "recasting" an existing polymorphic model instance to a more specific subclass type. The method takes an instance of a parent class and creates a child class instance with the same database ID and inherited data, effectively converting the object down the inheritance hierarchy.

Key Changes:

  • Adds create_from_super() method to PolymorphicManager for model recasting functionality
  • Implements validation to ensure objects can only be cast to direct child classes
  • Creates new test suite to verify recasting behavior across multiple inheritance levels

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.

File Description
src/polymorphic/managers.py Adds create_from_super manager method with validation, database operations, and content type updates to enable polymorphic recasting
src/polymorphic/tests/test_recasting.py Adds test suite covering successful recasting from Model2C→Model2D and error cases for non-adjacent inheritance levels

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bckohan bckohan marked this pull request as draft December 8, 2025 22:04
@bckohan
Copy link
Contributor Author

bckohan commented Dec 9, 2025

It might be best to solve this upstream in Django - a solution to this would also work for polymorphic models because they are just multi-table models with a fancy manager.

@bckohan bckohan force-pushed the create_from_super branch 4 times, most recently from 637a7d5 to 4e9272a Compare December 14, 2025 04:57
@bckohan bckohan marked this pull request as ready for review December 14, 2025 05:14
@bckohan bckohan requested a review from Copilot December 14, 2025 05:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Joshua <jcoxwell@gmail.com>
Co-authored-by: Brian Kohan <bckohan@gmail.com>
@bckohan bckohan merged commit e926e13 into master Dec 14, 2025
158 of 161 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a sub table row from existing parent.

2 participants