diff --git a/astropy/coordinates/sky_coordinate.py b/astropy/coordinates/sky_coordinate.py index ab475f7d0d29..661658b37342 100644 --- a/astropy/coordinates/sky_coordinate.py +++ b/astropy/coordinates/sky_coordinate.py @@ -867,10 +867,12 @@ def _is_name(self, string): ) def __getattr__(self, attr): - """ - Overrides getattr to return coordinates that this can be transformed - to, based on the alias attr in the primary transform graph. - """ + # If this attribute exists on the class (e.g., a subclass property), + # try to access it via normal attribute lookup so that any + # AttributeError raised by the descriptor propagates unchanged. + for cls in type(self).mro(): + if attr in getattr(cls, "__dict__", {}): + return object.__getattribute__(self, attr) if "_sky_coord_frame" in self.__dict__: if self._is_name(attr): return self # Should this be a deepcopy of self? @@ -2220,4 +2222,4 @@ def from_name(cls, name, frame="icrs", parse=False, cache=True): if frame in ("icrs", icrs_coord.__class__): return icrs_sky_coord else: - return icrs_sky_coord.transform_to(frame) + return icrs_sky_coord.transform_to(frame) \ No newline at end of file diff --git a/astropy/coordinates/tests/test_sky_coord_subclass_attr.py b/astropy/coordinates/tests/test_sky_coord_subclass_attr.py new file mode 100644 index 000000000000..a3196202ec7d --- /dev/null +++ b/astropy/coordinates/tests/test_sky_coord_subclass_attr.py @@ -0,0 +1,19 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +import pytest +import astropy.units as u +from astropy.coordinates import SkyCoord + +class CustomCoord(SkyCoord): + @property + def prop(self): + # Access a non-existent attribute to trigger AttributeError from the descriptor + return self.random_attr + + +def test_subclass_property_inner_attributeerror_message(): + c = CustomCoord('00h42m30s', '+41d12m00s', frame='icrs') + with pytest.raises(AttributeError) as excinfo: + _ = c.prop + # Ensure the error message mentions the missing inner attribute, not the property name + assert "random_attr" in str(excinfo.value) + assert "prop" not in str(excinfo.value)