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

TypeError: error: Incompatible types in assignment (expression has type "Clan", variable has type "Optional[ForeignKeyFieldInstance[Clan]]") #1314

Open
adambirds opened this issue Jan 1, 2023 · 0 comments

Comments

@adambirds
Copy link

adambirds commented Jan 1, 2023

Describe the bug
Getting a type error when updating the ForeignKey field to a different clan on a Nullable Foreign Key Field instance.

To Reproduce

if await Clan.get_or_none(tag=clantag):
	clan = await Clan.get(tag=clantag)
	if await Player.get_or_none(name=playername):
		if await Season.active_seasons.all().exists():
			await ctx.send("Cannot move players between clans during an active season.")
		else:
			player = await Player.get(name=playername)
			if player.is_enabled():
				player.clan = clan
				await player.save()
				await ctx.send(
					f"Welcome @{playername} to the [{clan.tag}] {clan.name} Clan roster!"
				)
			else:
				player.clan = clan
				await player.save()
				await ctx.send(
					f"Welcome @{playername} to the [{clan.tag}] {clan.name} Clan roster!"
				)
	else:
		await Player.create(name=playername, clan=clan, enabled=True)
		await ctx.send(
			f"Welcome @{playername} to the [{clan.tag}] {clan.name} Clan roster!"
		)
else:
	await ctx.send(f"Clan {clantag} does not exist.")

Expected behavior
This shouldn't error as the code works fine and foreign key field gets updated fine.

Additional context
Add any other context about the problem here.

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

No branches or pull requests

1 participant