'"bool" is incompatible with "Column[bool]"PylancereportGeneralTypeIssues
I am trying to update a simple record in Postgres table via FastAPI and SQL Alchmey.
My endpoint is as follows:
@app.patch(
"/edit-audience/{audience_id}",
response_model=schema.SignalJourneyAudiences,
status_code=status.HTTP_200_OK,
)
def edit_audience(
audience_id: int, sja: schema.SignalJourneyAudiences, db: Session = Depends(get_db)
):
"""Edits an audience from SignalJourneyAudiences."""
audience = (
db.query(models.SignalJourneyAudiences)
.filter(models.SignalJourneyAudiences.audience_id == audience_id)
.first()
)
audience.enabled = sja.enabled
return audience
its schema is :
class SignalJourneyAudiences(BaseModel):
"""SignalJourneyAudiences BaseModel."""
audience_id: Optional[int] # PK
segment: str
enabled: bool
class Config:
"""config class"""
orm_mode = True
and it's model is
class SignalJourneyAudiences(Base):
"""Signal Journey Audiences"""
__tablename__ = "SignalJourneyAudiences"
audience_id = Column(Integer, primary_key=True, autoincrement=True)
segment = Column(String)
enabled = Column(Boolean)
I am getting this error in VSC using PyLance and it make zero sense too me? As this is confusing as hell
"bool" is incompatible with "Column[bool]"PylancereportGeneralTypeIssues
(variable) enabled: bool
Cannot assign member "enabled" for type "SignalJourneyAudiences"
Expression of type "bool" cannot be assigned to member "enabled" of class "SignalJourneyAudiences"
"bool" is incompatible with "Column[bool]"PylancereportGeneralTypeIssues
"enabled" is not a known member of "None"PylancereportOptionalMemberAccess
This is how I will eventually call the endpoint and make the relevant update
// DELETES Audience from SignalJourneyAudiences
function deleteAudience(audience_id) {
console.log(segments);
console.log('aid', audience_id);
segments.map((segment) => {
if (audience_id === segment.audience_id && segment.enabled === false) {
try {
const deleteConstraint = fetch(
`http://localhost:8000/edit-audience/${audience_id}`,
{
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
enabled: true,
}),
}
);
if (deleteConstraint.status === 200) {
window.location.reload();
}
} catch (error) {
console.error(error);
}
}
if (audience_id === segment.audience_id && segment.enabled === true) {
try {
const deleteConstraint = fetch(
`http://localhost:8000/edit-audience/${audience_id}`,
{
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
enabled: false,
}),
}
);
if (deleteConstraint.status === 200) {
window.location.reload();
}
} catch (error) {
console.error(error);
}
}
});
}
Any Ideas on how to resolve this would be great, I am a bit of a loose end here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
