Lemmy.World
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
eifachposteBM to Kagi Small Web Appreciated RSS FeedEnglish · 1 day ago

Django Custom Managers Are Silently Leaking Data

johnnymetz.com

external-link
message-square
0
link
fedilink
0
external-link

Django Custom Managers Are Silently Leaking Data

johnnymetz.com

eifachposteBM to Kagi Small Web Appreciated RSS FeedEnglish · 1 day ago
message-square
0
link
fedilink
Django custom managers are a common way to exclude rows by default, such as inactive or soft-deleted rows. However, they don’t run everywhere you’d expect, which leads to unintended data exposure. This post covers where that happens and how to fix it. The Setup Let’s model stores and products with a soft-deletable relationship: class Store(models.Model): name = models.CharField(max_length=255) class Product(models.Model): name = models.CharField(max_length=255) class StoreProductManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(active=True) class StoreProduct(models.Model): store = models.ForeignKey(Store, on_delete=models.CASCADE) product = models.ForeignKey(Product, on_delete=models.CASCADE) active = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) objects = StoreProductManager() # default: active only all_objects = models.Manager() # escape hatch: everything The custom manager is declared first, making it the default manager. That feels like it should protect us everywhere, but it doesn’t.
alert-triangle
You must log in or # to comment.

Kagi Small Web Appreciated RSS Feed

kagismallweb

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 62 users / day
  • 178 users / week
  • 429 users / month
  • 555 users / 6 months
  • 42 local subscribers
  • 45 subscribers
  • 4.49K Posts
  • 98 Comments
  • Modlog
  • mods:
  • eifachposteB
  • UI: 0.19.16-8-g8cd34ec0
  • BE: 0.19.16-6-g1f680600c
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org