netbox
                                
                                 netbox copied to clipboard
                                
                                    netbox copied to clipboard
                            
                            
                            
                        API for L2VPN Termination does not work when using the __n suffix on some variables
NetBox version
v3.3-Beta2
Python version
3.10
Steps to Reproduce
1.) Create L2VPN and L2VPN termination connecting to a device interface 2.) Use the API endpoint /api/ipam/l2vpn-terminations either with interface__n=<interface_name> or interface_id__n=<interface_id>equalling to a valid input 3.) Send as GET Request and receive error
Expected Behavior
I expected a json response with a list of l2vpn terminations not equal to interface respectively interface_id
Observed Behavior
I received a html document containing a description of an attribute error:
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Server Error</title>
	<link rel="stylesheet" href="/static/netbox-light.css" />
	<meta charset="UTF-8">
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col col-md-6 offset-md-3">
				<div class="card border-danger mt-5">
					<h5 class="card-header">
						<i class="mdi mdi-alert"></i> Server Error
					</h5>
					<div class="card-body">
						<p>
							There was a problem with your request. Please contact an administrator.
						</p>
						<hr />
						<p>
							The complete exception is provided below:
						</p>
						<pre class="block"><strong><class 'AttributeError'></strong><br />
'GenericRelation' object has no attribute 'field'
Python version: 3.10.4
NetBox version: 3.3-beta2</pre>
						<p>
							If further assistance is required, please post to the <a
								href="https://github.com/netbox-community/netbox/discussions">NetBox discussion
								forum</a> on GitHub.
						</p>
						<div class="text-end">
							<a href="/" class="btn btn-primary">Home Page</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
When excluding l2vpn_id with l2vpn_id__n it works just fine.
I believe this is a DJango limitation, it looks like the __n is not properly implemented for GFK's using the reverse "GenericRelation". We could feed this to a function, but we explicitly exclude the function from generating the other reverse lookups as well.
This problem pops up if you do a manual query with exclude() on any Genericrelated key as well.
Unfortunately, I don't know of a good way to do this, perhaps @kkthxbye-code or @jeremystretch might have a way around this. I found this information on SO: https://stackoverflow.com/questions/41730894/django-genericrelated-field-conditional-query-raising-genericrelation-object-h and it looks like the normal way is to do a subquery or a conditional expression.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.
This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.