Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vesion 3.1.5 returns null for an object pointed to non PK in referred table. #1482

Open
3hedgehogs opened this issue Dec 6, 2023 · 3 comments
Labels

Comments

@3hedgehogs
Copy link

Version 3.1.3 and older versions are working correctly in situation if a field is a foreign key to a non PK of pointed table.
3.1.5 returns 'null'

@kiendang
Copy link
Collaborator

kiendang commented Dec 6, 2023

@3hedgehogs Could you provide some example code/a reproducible example? Would be great if you follow the template for bug report too.

@3hedgehogs
Copy link
Author

3hedgehogs commented Dec 6, 2023

Unfortunately I'm not a django programmer, just temporary support our internal project till we find a person to continue develop it.

Used models:

class HourlyLimit(mta_gui.models.MultiSettingsExtension, mta_gui.models.Model):
    id = models.AutoField(db_column="limitid", primary_key=True)
    source = models.ForeignKey(
        to="pools.IpAddress",
        on_delete=models.CASCADE,
        db_column="OutPort",
        to_field="outport",
        related_name="hourly_limits",
    )
    destination = models.ForeignKey(
        to="destinations.Destination",
        on_delete=models.CASCADE,
        db_column="DestinationId",
        related_name="hourly_limits",
        help_text="DEFAULT means limit is for all destinations",
    )
    value = models.IntegerField(
        db_column="Value", default=0, help_text="0 means this public IP is disabled"
    )
    memo = models.TextField(db_column="Memo", blank=True, null=True)
...

class IpAddress(mta_gui.models.MultiSettingsExtension, mta_gui.models.Model):
    id = models.AutoField(db_column="IpId", primary_key=True)
    ip = models.CharField(db_column="Ip", max_length=60, unique=True)
    ip_range = models.ForeignKey(
        to="IpRange",
        on_delete=models.CASCADE,
        db_column="ipRangeId",
        related_name="ip_addresses",
    )
    domain = models.CharField(db_column="Note", max_length=255)
    outport = models.SmallIntegerField(db_column="OutPort", unique=True)
    ip_pools = models.ManyToManyField(IpPool, related_name="ip_pools")
    ip_pool = models.ForeignKey(
        to="IpPool",
        on_delete=models.SET_NULL,
        db_column="IpPoolId",
        blank=True,
        null=True,
        related_name="ip_addresses",
        verbose_name="IP pool",
    )
...

destination is returned correctly but
source is always null for version 3.1.5

Sorry, if information is not enough I will close this issue

@kiendang
Copy link
Collaborator

kiendang commented Dec 6, 2023

Unfortunately I'm not a django programmer, just temporary support our internal project till we find a person to continue develop it.

I see. Would definitely prefer a minimum reproducible example so we can create a test for it and see which change caused the issue, but I understand your situation. You can leave the issue open.

There're not a lot of PRs merged from 3.1.3 to 3.1.5. I suspect it's due to either #1411 or #1446.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants